Created
February 7, 2022 03:42
-
-
Save amarjitdhillon/ad7e0576b97744014c84365cf83539c3 to your computer and use it in GitHub Desktop.
Find Peak Element
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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