当前位置:网站首页>leetcode 240. Search a 2D Matrix II 搜索二维矩阵 II(中等)
leetcode 240. Search a 2D Matrix II 搜索二维矩阵 II(中等)
2022-08-05 12:22:00 【InfoQ】
一、题目大意
- m == matrix.length
- n == matrix[i].length
- 1 <= n, m <= 300
- -109 <= matrix[i][j] <= 109
- 每行的所有元素从左到右升序排列
- 每列的所有元素从上到下升序排列
- -109 <= target <= 109
二、解题思路
三、解题方法
3.1 Java实现
public class Solution {
public boolean searchMatrix(int[][] matrix, int target) {
// 从右上角开始搜索,比target大就向左移,比target小就向下移
int x = matrix.length - 1;
int y = 0;
while (x >=0 && y < matrix[0].length) {
if (matrix[x][y] == target) {
return true;
} else if (matrix[x][y] > target) {
x--;
} else {
y++;
}
}
return false;
}
}
四、总结小记
- 2022/8/5 疫情啊,什么时候能消停一会
边栏推荐
猜你喜欢
随机推荐
MySQL's InnoDB thread model
C语言经典例题-求一串数中的最大数
Small household appliance industry supply chain collaborative management system: help enterprises break through market competition and strengthen the rapid response capability of the supply chain
Memory problems difficult to locate, it is because you do not use ASAN
C语言例题-计算常量e的值
通俗易懂玩QT:QT程序发布打包
尚硅谷-JVM-内存和垃圾回收篇(P1~P203)
Shang Silicon Valley-JVM-Performance Monitoring and Tuning (P302~P381)
到底怎么个DAO
台州亿丰克瑞斯伺服驱动器调试说明
小家电行业供应链协同管理系统:助力企业突围市场竞争,加强供应链快速响应能力
798. Difference Matrix
Sentinel introduction and use
798. 差分矩阵
solaris-oralce rac 安装
我和 TiDB 的故事 | 学tidb半年,社区治好了我的精神内耗
The memory problem is difficult to locate, that's because you don't use ASAN
796. Sum of Submatrices
2022.08.01_Daily Question
MYSQL 查询重复数据









