Update 4. 二维数组中的查找.md

题目链接改为力扣中的对应题目,题目描述和代码按该题的接口调整。
This commit is contained in:
CyC2018
2026-10-28 13:45:05 +08:00
parent 8cce3778d5
commit 6378a85835
+6 -6
View File
@@ -2,7 +2,7 @@
## 题目链接
[牛客网](https://www.nowcoder.com/practice/abc3fe2ce8e146608e868a70efebf62e?tpId=13&tqId=11154&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking&from=cyc_github)
[Leetcode](https://leetcode.cn/problems/er-wei-shu-zu-zhong-de-cha-zhao-lcof/)
## 题目描述
@@ -31,15 +31,15 @@ Given target = 20, return false.
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/35a8c711-0dc0-4613-95f3-be96c6c6e104.gif" width="400px"> </div><br>
```java
public boolean Find(int target, int[][] matrix) {
if (matrix == null || matrix.length == 0 || matrix[0].length == 0)
public boolean findTargetIn2DPlants(int[][] plants, int target) {
if (plants == null || plants.length == 0 || plants[0].length == 0)
return false;
int rows = matrix.length, cols = matrix[0].length;
int rows = plants.length, cols = plants[0].length;
int r = 0, c = cols - 1; // 从右上角开始
while (r <= rows - 1 && c >= 0) {
if (target == matrix[r][c])
if (target == plants[r][c])
return true;
else if (target > matrix[r][c])
else if (target > plants[r][c])
r++;
else
c--;