Leetcode 154. Find Minimum in Rotated Sorted Array II

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

1. Description

Find Minimum in Rotated Sorted Array II

2. Solution

class Solution {
public:
    int findMin(vector& 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++;
            }
            else 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-ii/description/

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