154. Find Minimum in Rotated Sorted Array II
就比1多了一点点
1 public int findMin(int[] nums) { 2 if(nums.length == 0) { 3 return -1; 4 } 5 int left = 0; 6 int right = nums.length - 1; 7 while(left < right) { 8 int mid = left + (right - left) / 2; 9 if(nums[mid] > nums[right]) { 10 left = mid + 1; 11 } else if(nums[mid] < nums[right]) { 12 right = mid; 13 } else { 14 right--; 15 } 16 } 17 return nums[left]; 18 }
第13行,当nums[mid] == nums[high]的时候high--