Find Minimum in Rotated Sorted Array

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.

You may assume no duplicate exists in the array.

class Solution:
    # @param num, a list of integer
    # @return an integer
    def findMin(self, num):
        left,right = 0,len(num)-1
        while left <= right:
            if left == right:
                return num[left] 
            mid = left+(right-left)/2
            if num[mid] >= num[left] and num[mid] > num[right]:
                left = mid + 1
            elif num[mid]


你可能感兴趣的:(leetcode,min)