//二分法判断一个数是否存在(有序数组)
public static Boolean BSExist(int[] arr, int num) {
if (arr == null || arr.length == 0) {
return false;
}
int L = 0;
int R = arr.length - 1;
int mid = 0;
while (R > L) {
mid = L + (R - L) >> 1;
if (arr[mid] == num) {
return true;
} else if (arr[mid] > num) {
R = mid - 1;
} else {
L = mid + 1;
}
}
return arr[L] == num;
}
标签:arr,return,int,mid,二分法,num,004
From: https://www.cnblogs.com/ppku/p/16775689.html