Create find_peak_element.py

This commit is contained in:
marina 2023-07-31 15:57:30 -07:00 committed by GitHub
parent d0bbfed0e5
commit 06f3c4dd1e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -0,0 +1,21 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# author: bt3gl
# A peak element is an element that is strictly greater than its neighbors.
def peak_element(nums):
left, right = 0, len(nums) - 1
while left < right:
mid = (left + right) // 2
if nums[mid] > nums[mid + 1]:
right = mid
else:
left = mid + 1
return left