
(图片来源https://leetcode-cn.com/problems/search-a-2d-matrix/
)
日期 | 是否一次通过 | comment |
---|---|---|
2020-03-10 | 1 |
public boolean searchMatrix(int[][] matrix, int target) {
if(matrix == null || matrix.length < 1 || matrix[0].length < 1) {
return false;
}
int r = matrix.length-1, c = 0;
int re = matrix.length-1, ce = matrix[0].length-1;
while(r >= 0 && c >= 0 && r <= re && c <= ce) {
if(matrix[r][c] == target) {
return true;
}
if(matrix[r][c] > target) {
r --;
} else {
c ++;
}
}
return false;
}
网友评论