跳转至

寻找旋转排序数组中的最小值 II⚓︎

Leetcode题目链接

描述⚓︎

详见中文题目链接

解答⚓︎

class Solution {
public:
    int findMin(vector<int>& nums) {
        int left = -1, right = nums.size() - 1;
        while (left + 1 < right && nums[right] == nums[0]) right--;
        if (nums[0] <= nums[right]) return nums[0];

        while (left + 1 < right) {
            int mid = left + right >> 1;
            if (nums[mid] >= nums[0]) left = mid;
            else right = mid;
        }

        return left == nums.size() - 1 ? nums[0] : nums[left + 1];
    }
};