Leetcode 153. Find Minimum in Rotated Sorted Array

文章作者:Tyan
博客:noahsnail.com  |  CSDN  |  简书

1. Description

2. Solution

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

Reference

  1. https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/description/

你可能感兴趣的:(Leetcode,Leetcode)