mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-30 04:36:08 -04:00
22 lines
417 B
Python
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 + 1] < nums[mid]:
|
|
right = mid
|
|
else:
|
|
left = mid + 1
|
|
|
|
return left
|
|
|