154. Find Minimum in Rotated Sorted Array II

https://www.cnblogs.com/habibah-chang/p/12538877.html

附加条件,允许重复数值。

Example 1:
Input: [1,3,5]
Output: 1

Example 2:
Input: [2,2,2,0,1]
Output: 0

  

方法:

思想同上述链接题目,二分查找

附加处理:

如果mid==low的值,那么不确定low~mid都是一样的值,还是其中存在最小值。

那么,只能high--,一项一项移动来确定。

参考代码:

 1 class Solution {
 2 public:
 3     int findMin(vector<int>& nums) {
 4         int low=0, high=nums.size()-1;
 5         while(low<high){
 6             if(nums[low]<nums[high]) return nums[low];
 7             int mid=(low+high)/2;
 8             if(nums[mid]>=nums[low]){
 9                 if(nums[mid]==nums[high]) high--;//★
10                 else low=mid+1;
11             }else{
12                 high=mid;
13             }
14         }
15         return nums[low];
16     }
17 };
原文地址:https://www.cnblogs.com/habibah-chang/p/12538919.html