思路:同剑指offer no,4
// @Title: 搜索二维矩阵 II (Search a 2D Matrix II)
// @Author: qisiii
// @Date: 2022-02-06 23:06:53
// @Runtime: 6 ms
// @Memory: 47.4 MB
// @comment: 同剑指offer no,4
// @flag: GREEN
class Solution {
public static boolean searchMatrix(int[][] matrix, int target) {
if (matrix == null || matrix.length == 0 || matrix[0].length == 0) {
return false;
}
int rows = matrix.length, columns = matrix[0].length;
int row = 0, column = columns - 1;
while (row<rows&&column>=0){
if (target==matrix[row][column]){
return true;
}else if(target>matrix[row][column]){
row++;
}else {
column--;
}
}
return false;
}
}