Leetcode---剑指Offer题11---旋转数组中的最小值(二分法
剑指Offer-面试题11---旋转数组中的最小值
1、旋转数组中的最小值
https://leetcode-cn.com/problems/xuan-zhuan-shu-zu-de-zui-xiao-shu-zi-lcof/
二分法
public int MinArray(int[] numbers)
{
if (numbers==null || numbers.Length<1)
return -1;
int left = 0;
int right = numbers.Length - 1;
int mid = 0;
while (left < right)
{
mid = (left + right) >> 1;
if (numbers[mid] > numbers[right])
{
left = mid + 1;
}
else if (numbers[mid] == numbers[right])
{
right--;
}
else
{
right = mid;
}
}
return numbers[left];
}