Skip to content

Latest commit

 

History

History
30 lines (21 loc) · 465 Bytes

File metadata and controls

30 lines (21 loc) · 465 Bytes

Peak Index in a Mountain Array

Description

link


Solution

  • See Code

Code

O(log(n))

class Solution:
    def peakIndexInMountainArray(self, A: List[int]) -> int:
        l, r = 0, len(A) - 1
        while l < r:
            m = (l + r) // 2
            if A[m] < A[m+1]:
                l = m + 1
            else:
                r = m
        return l