-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlintcode_585.py
More file actions
23 lines (21 loc) · 649 Bytes
/
Copy pathlintcode_585.py
File metadata and controls
23 lines (21 loc) · 649 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Solution:
"""
@param nums: a mountain sequence which increase firstly and then decrease
@return: then mountain top
"""
def mountainSequence(self, nums):
# write your code here
if nums == None or len(nums) == 0:
return -1
start = 0
end = len(nums) - 1
while start + 1 < end:
mid = start + (end - start) // 2
if nums[mid] > nums[mid - 1]:
start = mid
elif nums[mid] > nums[mid + 1]:
end = mid
if nums[start] > nums[end]:
return nums[start]
else:
return nums[end]