// 从左下角往右上脚遍历
class Solution {
public boolean searchMatrix(int[][] matrix, int target) {
int row = matrix.length - 1;
int col = 0;
while (row >= 0 && col < matrix[0].length) {
if (matrix[row][col] < target) {
col++;
} else if (matrix[row][col] > target) {
row--;
} else {
return true;
}
}
return false;
}
}
Hot100【十一】:240. 搜索二维矩阵 II
最新推荐文章于 2024-09-13 16:27:12 发布
该篇文章介绍了如何在给定的二维整数矩阵中,使用类Solution的searchMatrix方法从左下角向右上角遍历,查找目标值是否存在。
摘要由CSDN通过智能技术生成