Find Minimum in Rotated Sorted Array

地址:https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/
题意为旋转数组中的最小数
剑指offer里有,所以很快就解决了。二分

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

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