Leetcode 11 旋转数组的最小数字
将一个排好序的数组中截断前一部分(长度不定)拼接到数组最后形成一个新的数组,求该数组中的最小值。
二分查找
class Solution {
public int minArray(int[] numbers) {
int low = 0;
int high = numbers.length - 1;
while (low < high) {
int pivot = low + (high - low) / 2;
if (numbers[pivot] < numbers[high]) {
high = pivot;
} else if (numbers[pivot] > numbers[high]) {
low = pivot + 1;
} else {
//应对重复问题(左右两端有可能存在连续重复的数字)
high -= 1;
}
}
return numbers[low];
}
}