154. Find Minimum in Rotated Sorted Array II

当遇见重复的时候r--.
为什么不是l++呢?因为我们总是在比较nums[mid] nums[r]

int findMin(int* nums, int numsSize) {
    int l = 0;
    int r = numsSize-1;
    int mid = 0;
    while(l+1 < r){
        mid = l + (r-l)/2;
        if(nums[mid] < nums[r])
            r = mid;
        else if(nums[mid] > nums[r])
            l = mid;
        else
            r--;
    }
    
    if(nums[l] < nums[r])
        return nums[l];
    
    return nums[r];
    
}

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