今天刷题刷到了一个二分查找的题目,对于二分查找的理解还不是很透彻,记录一下问题,还暂时不明白原理。
int mid = (right - left + 1) / 2 + left;
left = mid ;
下标是调试出来的暂时不清楚原理,以后再来补一个下吧。
public int searchRow(int[][] matrix,int target) {
int left = 0;
int right = matrix.length - 1;
while (left < right) {
int mid = (right - left + 1) / 2 + left;
if(matrix[mid][0] <= target) {
left = mid ;
} else {
right = mid -1;
}
}