- 右上角或左下角开始寻找
- 优化方向:每次不一定只向下或向左移一位,用二分的思想找到连续同方向移动的终止坐标
class Solution {
public boolean findNumberIn2DArray(int[][] matrix, int target) {
if(matrix.length==0) return false;
int m = matrix.length;
int n = matrix[0].length;
int i = 0;
int j = n-1;
while(i<=m-1 && j>=0){
if(matrix[i][j]==target) return true;
if(matrix[i][j]>target){
j--;
}else{
i++;
}
}
return false;
}
}