选右上角。时间复杂度:O(n+m),最多m减完然后n减完。
class Solution {
public boolean findNumberIn2DArray(int[][] matrix, int target) {
if(matrix.length < 1 || matrix == null){
return false;
}
int m = matrix[0].length-1;
int i = 0;
while(i < matrix.length && m >= 0 ){
if(matrix[i][m] > target){
m--;
}else if(matrix[i][m] < target){
i++;
}else{
return true;
}
}
return false;
}
}