1、二分法求旋转数组的最小数
/**
* 利用二分法求旋转数组的最小数:
*
* 3,4,5,1,2
* 1 0 1 1 1
* 1 1 1 0 1
*
* */
public static int getMin(int[] arr){
int start=0;
int end=arr.length-1;
boolean flag=false;
while(arr[start]>arr[end]){
int mid=(start+end)/2;
if(start+1==end){
return arr[end];
}
if(arr[mid]>arr[start]){
start=mid;
}else if(arr[mid]<arr[end]){
end=mid;
}
}
int mid=(start+end)/2;
while(arr[start]==arr[mid]){
if(start+1==mid){
break;
}
mid--;
}
while(arr[end]==arr[mid]){
if(end==mid+1){
break;
}
mid++;
}
return arr[mid];
}