-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path162.py
37 lines (26 loc) · 830 Bytes
/
162.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = ['"wuyadong" <[email protected]>']
class Solution(object):
def findPeakElement(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
start = 0
end = len(nums)-1
while start <= end:
mid = (start+end)/2
if mid == start or mid == end:
return start if nums[start] > nums[end] else end
if nums[mid-1] < nums[mid] and nums[mid] > nums[mid+1]:
return mid
elif nums[mid-1] < nums[mid]:
start = mid
elif nums[mid] > nums[mid+1]:
end = mid
else:
start = mid
return start
if __name__ == "__main__":
print Solution().findPeakElement([1, 2])