首页 > 代码库 > [leetcode]Find Minimum in Rotated Sorted Array

[leetcode]Find Minimum in Rotated Sorted Array

很眼熟。。。就是一个二分。。。

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

 

[leetcode]Find Minimum in Rotated Sorted Array