0.code
class Solution {
public boolean findNumberIn2DArray(int[][] matrix, int target) {
if(matrix==null||matrix.length==0||matrix[0].length==0){
return false;
}
int row = matrix.length-1;
int col = matrix[0].length-1;
int startRow = 0;
int startCol = col;
while(true){
if(startRow>row){
return false;
}
if(startCol<0){
return false;
}
if(matrix[startRow][startCol]==target){
return true;
}
if(matrix[startRow][startCol]>target){
startCol--;
continue;
}
if(matrix[startRow][startCol]<target){
startRow++;
continue;
}
}
}
}
网友评论