跳转至

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

Leetcode题目链接

描述⚓︎

详见中文题目链接

解答⚓︎

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