Skip to content

Instantly share code, notes, and snippets.

@priyankvex
Created September 18, 2019 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save priyankvex/e09c55155a087ccbf46a8650ee2fbab8 to your computer and use it in GitHub Desktop.
Save priyankvex/e09c55155a087ccbf46a8650ee2fbab8 to your computer and use it in GitHub Desktop.
Find the peak element
class Solution:
def findPeakElement(self, a):
low = 0
high = len(a) - 1
ans = self.helper(a, low, high)
return ans
def helper(self, a, low, high):
if low >= high:
return low
mid = int((low + high) / 2)
if a[mid] < a[mid+1]:
return self.helper(a, mid+1, high)
if a[mid] >= a[mid+1]:
return self.helper(a, low, mid)
if __name__ == "__main__":
a = [2, 1, 3]
ans = Solution().solve(a)
print(ans)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment