Skip to content

Commit

Permalink
Merge pull request #2647 from TheHong/py-0162
Browse files Browse the repository at this point in the history
Create 0162-find-peak-element.py
  • Loading branch information
tahsintunan committed Jun 29, 2023
2 parents d691b58 + c3bdd6e commit 8822cd5
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions python/0162-find-peak-element.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Solution:
def findPeakElement(self, nums: List[int]) -> int:
l, r = 0, len(nums) - 1
while l <= r:
mid = (r + l) // 2
if mid < len(nums) - 1 and nums[mid] < nums[mid+1]:
l = mid + 1
elif mid > 0 and nums[mid] < nums[mid-1]:
r = mid - 1
else:
break
return mid

0 comments on commit 8822cd5

Please sign in to comment.