讨论/《图解算法数据结构》 - 剑指 Offer 11. 旋转数组的最小数字/
《图解算法数据结构》 - 剑指 Offer 11. 旋转数组的最小数字

二分查找

class Solution {
    public int minArray(int[] numbers) {
        int n = numbers.length;
        if(n == 1)  return numbers[0];
        int left = 0;
        int right = n-1;
        int mid;
        while(left < right){
            mid = (left+right)/2;
            if(numbers[mid] < numbers[right]){
                right = mid;
            }
            else if(numbers[mid] > numbers[right]){
                left = mid+1;
            }
            else{
                if(left<right && numbers[left] == numbers[mid]){
                    left++;
                }
                if(left<right && numbers[right] == numbers[mid]){
                    right--;
                }
            }
        }
        return numbers[left];
    }
}
展开全部 5 讨论