第一种[left, right]
public static int search(int[] arr,int target) {
int l = 0;
int r = arr.length - 1;
while (l <= r){
int m = (l + r) >> 1;
if (arr[m] == target){
return m;
}else if (arr[m] < target){
l = m + 1;
}else {
r = m - 1;
}
}
return -1;
}
第二种[left, right)
public static int search(int[] arr,int target) {
int l = 0;
int r = arr.length ;
while (l < r){
int m = (l + r) >> 1;
if (arr[m] == target){
return m;
}else if (arr[m] < target){
l = m + 1;
}else {
r = m;
}
}
return -1;
}