master-algorithms-py/searching/find_peak_element.py
2023-07-31 15:57:30 -07:00

22 lines
417 B
Python

#!/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