/**
* 二分查找,寻找目标值的下标,如果找到返回下标,如果没有返回-1
* @param list
* @param target
* @return
*/
public int binarySearch(int[] list, int target){
int low = 0, high = list.length-1;
while(low <= high){
int middle = (low + high)/2;
if(list[middle] == target){
return middle;
}
if(list[middle] < target){
high = middle - 1;
}
if(list[middle] > target){
low = middle + 1;
}
}
return -1;
}