classSolution { publicstaticint n; publicstaticint m; publicbooleansearchMatrix(int[][] matrix, int target) { n = matrix.length; m = matrix[0].length; intl= -1 , r = n * m;
while(l + 1 < r){ intmid= l + r >> 1; intx= get(mid)[0], y = get(mid)[1]; if(matrix[x][y] >= target){ r = mid; }else{ l = mid; } }
if(r >= n * m){ returnfalse; }
return matrix[get(r)[0]][get(r)[1]] == target; }
// 将一维 坐标转化为 二维 publicint [] get(int x){ returnnewint []{x / m , x % m}; } }