File tree Expand file tree Collapse file tree 3 files changed +26
-0
lines changed Expand file tree Collapse file tree 3 files changed +26
-0
lines changed Original file line number Diff line number Diff line change 86
86
234. 回文链表
87
87
236. 二叉树的最近公共祖先
88
88
239. 滑动窗口最大值
89
+ 240. 搜索二维矩阵 II
89
90
279. 完全平方数
90
91
283. 移动零
91
92
287. 寻找重复数
Original file line number Diff line number Diff line change 152
152
169. 多数元素(排序,哈希表,投票,计数,分治)
153
153
215. 数组中的第K个最大元素(快速排序,堆排序)
154
154
239. 滑动窗口最大值(单调递减双端队列)
155
+ 240. 搜索二维矩阵 II(二分查找)
155
156
283. 移动零(双指针)
156
157
287. 寻找重复数(哈希表,快慢指针,二分查找,位运算)
157
158
303. 区域和检索 - 数组不可变(前缀和)
Original file line number Diff line number Diff line change
1
+ // 240. 搜索二维矩阵 II
2
+
3
+
4
+ /*
5
+ 二分查找:
6
+ 1、从左下角开始,在有效边界范围内,元素小于目标值则右移,元素大于目标值则上移
7
+ 2、如果找到了目标值则返回true,遍历结束后没找到目标值则返回false
8
+ */
9
+ class Solution {
10
+ public boolean searchMatrix (int [][] matrix , int target ) {
11
+ int m = matrix .length , n = matrix [0 ].length ;
12
+ int row = m - 1 , col = 0 ;
13
+ while (row >= 0 && col < n ) {
14
+ if (matrix [row ][col ] == target ) {
15
+ return true ;
16
+ } else if (matrix [row ][col ] < target ) {
17
+ col ++;
18
+ } else {
19
+ row --;
20
+ }
21
+ }
22
+ return false ;
23
+ }
24
+ }
You can’t perform that action at this time.
0 commit comments