int findMin(vector<int>& nums) {
int start = 0;
int end = nums.size() - 1;
while(start + 1 < end){
int mid = start + (end - start)/2;
if(nums[mid] < nums[end]){
end = mid;
}
else{
start = mid;
}
}
if(nums[start] > nums[end]){
return nums[end];
}
else{
return nums[start];
}
}
就是二分搜索的简单运用,区别在于不断和 end 所在的数进行比较大小,从而更新 start 和 end
---------------------
findMax:
同理,唯一的区别在于不断和 start 所在的数进行比较大小