classSolution{ publicbooleanfindNumberIn2DArray(int[][] matrix, int target){ if(matrix.length==0|| matrix[0].length==0){ returnfalse; } int m = 0; int n = matrix[0].length-1; //从右上角开始找 while (n>=0 && matrix.length>m){ int res = matrix[m][n]; //如果大于目标值 if(res>target){ n--; }elseif(res<target){ m++; }elseif(res==target){ returntrue; } } returnfalse; } }