Suppose a sorted array is rotated at some pivot unknown to you beforehand.
(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).
Find the minimum element.
Example
Given [4, 5, 6, 7, 0, 1, 2] return 0
Notice
You may assume no duplicate exists in the array.
class Solution:
"""
@param nums: a rotated sorted array
@return: the minimum number in the array
"""
def findMin(self, nums):
# write your code here
left, right = 0, len(nums)-1
mid = int((left+right)/2)
while left < right:
print('left:', left)
print('mid:', mid)
print('right:', right)
print(' ')
if nums[mid]<=nums[right]:
right = mid
else:
left = mid + 1
mid = int((left+right)/2)
return nums[mid]