153. Find Minimum in Rotated Sorted Array

153. Find Minimum in Rotated Sorted Array_第1张图片
image.png
class Solution {
public:
    int findMin(vector& 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 + 1;
        }
        return min(nums[start], nums[end]);
    }
};

你可能感兴趣的:(153. Find Minimum in Rotated Sorted Array)