思路:
// @Title: 搜索二维矩阵 (Search a 2D Matrix)
// @Author: qisiii
// @Date: 2024-10-13 22:14:54
// @Runtime: 0 ms
// @Memory: 41.1 MB
// @comment:
// @flag: GREEN
class Solution {
public boolean searchMatrix(int[][] matrix, int target) {
int x=0,y=matrix[0].length-1;
while(x<matrix.length&&y>=0){
if(matrix[x][y]>target){
y--;
}else if(matrix[x][y]<target){
x++;
}else{
return true;
}
}
return false;
}
}