Skip to content

Instantly share code, notes, and snippets.

@amarjitdhillon
Created February 7, 2022 03:42
Show Gist options
  • Save amarjitdhillon/ad7e0576b97744014c84365cf83539c3 to your computer and use it in GitHub Desktop.
Save amarjitdhillon/ad7e0576b97744014c84365cf83539c3 to your computer and use it in GitHub Desktop.
Find Peak Element
class Solution:
def findPeakElement(self, nums: List[int]) -> int:
l, r = 0, len(nums)-1
while(l < r):
m = (l+r)//2
if nums[m] > nums[m+1]: # peak is at left for sure, so update the r pointer
r = m
else : # peak is at right for sure, so update l pointer
l = m+1
return l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment