class Solution {
public:
int func(vector<int>& nums,int begin,int end){
while(begin + 1 < end){
int mid = begin + ((end - begin) >>1);
if(nums[mid] == nums[begin] && nums[mid] == nums[end]){
int min = nums[begin];
for(int i = begin;i<=end;i++){
if(min > nums[i]) min = nums[i];
}
return min;
}
if(nums[mid] >= nums[begin]) //左侧有序
begin = mid;
else
end = mid;
}
return nums[end];
}
int findMin(vector<int>& nums) {
int begin = 0;
int end = nums.size()-1;
if(nums.size() == 0) return -1;
if(nums[begin] < nums[end]) return nums[begin];//考虑没有旋转的情况
int res = func(nums,begin,end);
return res;
}
};
标签:begin,end,22,nums,int,mid,return,Acwing
From: https://www.cnblogs.com/poteitoutou/p/17153030.html