lintcode 159. 寻找旋转排序数组中的最小值
2018-08-31 本文已影响2人
cuizixin
难度:中等
1. Description
159. 寻找旋转排序数组中的最小值2. Solution
- python
时间复杂度
class Solution:
"""
@param nums: a rotated sorted array
@return: the minimum number in the array
"""
def findMin(self, nums):
# write your code here
if nums[-1]>nums[0]:
return nums[0]
else:
start = 0
end = len(nums)-1
while end-start>1:
mid = (start+end)//2
if nums[mid]<nums[end]:
end = mid
elif nums[mid]>nums[start]:
start = mid
return min(nums[start],nums[end])