[leetcode]Find Minimum in Rotated Sorted Array

1731 ワード

見覚えがあります...二点です...
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];
    }
};