Skip to content

Commit 8822cd5

Browse files
authored
Merge pull request neetcode-gh#2647 from TheHong/py-0162
Create 0162-find-peak-element.py
2 parents d691b58 + c3bdd6e commit 8822cd5

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

python/0162-find-peak-element.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
def findPeakElement(self, nums: List[int]) -> int:
3+
l, r = 0, len(nums) - 1
4+
while l <= r:
5+
mid = (r + l) // 2
6+
if mid < len(nums) - 1 and nums[mid] < nums[mid+1]:
7+
l = mid + 1
8+
elif mid > 0 and nums[mid] < nums[mid-1]:
9+
r = mid - 1
10+
else:
11+
break
12+
return mid
13+

0 commit comments

Comments
 (0)