leetcode 剑指 Offer 11. 旋转数组的最小数字

leetcode

C++:

class Solution {
public:
    int minArray(vector& numbers) {

        if ( numbers.empty() ) {

            return 0;
        }

        int left = 0;
        int right = numbers.size() - 1;
        while ( left < right ) {

            int middle = left + ( right - left ) / 2;
            if ( numbers[middle] > numbers[right] ) {

                left = middle + 1;

            } else if ( numbers[middle] < numbers[right] ) {

                right = middle;

            } else {

                --right;
            }
        }

        return numbers[left];
    }
};

你可能感兴趣的:(leetcode 剑指 Offer 11. 旋转数组的最小数字)