Skip to main content

852. Peak Index in a Mountain Array

https://leetcode.com/problems/peak-index-in-a-mountain-array/

Python

class Solution:
def peakIndexInMountainArray(self, arr: List[int]) -> int:
left, right = 0, len(arr)-1

while left <= right:
pivot = (left+right) >> 1

if arr[pivot+1] < arr[pivot] and arr[pivot-1] < arr[pivot]:
return pivot

if arr[pivot+1] > arr[pivot]:
left = pivot + 1
else:
right = pivot