做过最简单的中等题,纪念一下
class Solution {
public boolean searchMatrix(int[][] matrix, int target) {
int rows = matrix.length;
int cols = matrix[0].length;
if(matrix[0][0] > target) return false;
for(int i = 0; i < rows; i++){
if(matrix[i][0] <= target && matrix[i][cols - 1] >= target){
for(int j = 0; j < cols; j++){
if(matrix[i][j] == target)
return true;
}
} else {
continue;
}
}
return false;
}
}