题目链接:https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array/
题目如下:
class Solution {
public:
int findMin(vector<int>& nums) {
int low=0,high=nums.size()-1;
while(low<=high){
int mid=low+(high-low)/2;
if(low==high) return nums[mid];
//先处理命中,在处理不命中
if((mid!=0&&nums[mid]<nums[mid-1])||(mid==0&&nums[mid]<nums[high])) return nums[mid];
else if(nums[mid]>nums[high]) low=mid+1;//左边有序,右边循环有序
else high=mid-1;//左边循环有序,右边有序
}
return -1;
}
};