154 Find Minimum in Rotated Sorted Array 2
这道题与 153 Find Minimum in Rotated Sorted Array 基本相同,只是有可能有重复的数字, 这样a[left] 就可能与a[mid]相同 因此就多一个可能,因此在最坏的情况下复杂度会是O(n)
class Solution: # @param {integer[]} nums # @return {integer} def findMin(self, nums): l = len(nums) - 1 if l <= 1: return min(nums) mid = l / 2 if nums[0] < nums[mid]: return self.findMin([nums[0]] + nums[mid+1:]) elif nums[0] > nums[mid]: return self.findMin(nums[1:mid+1]) else: return min(self.findMin(nums[0:mid]),self.findMin(nums[mid+1:]))