Skip to content

Commit c3bdd6e

Browse files
authored
Create 0162-find-peak-element.py
1 parent 39611ac commit c3bdd6e

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)