Maximum Number in Mountain Sequence
解析 :
class Solution:
# @param {int[]} nums a mountain sequence which increase firstly and then decrease
# @return {int} then mountain top
def mountainSequence(self, nums):
# Write your code here
# return max(nums)
start = 0
end = len(nums)-1
while start + 1 < end:
mid = (start+end)/2
# find out if on downhill or uphill
# uphill
if nums[mid] < nums[mid+1]:
start = mid
# downhill
else:
end = mid
if nums[start]>nums[end]:
return nums[start]
return nums[end]Last updated