From 6378a85835b6de2f48cc3a3bc431e81fb1659158 Mon Sep 17 00:00:00 2001 From: CyC2018 Date: Wed, 28 Oct 2026 13:45:05 +0800 Subject: [PATCH] =?UTF-8?q?Update=204.=20=E4=BA=8C=E7=BB=B4=E6=95=B0?= =?UTF-8?q?=E7=BB=84=E4=B8=AD=E7=9A=84=E6=9F=A5=E6=89=BE.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 题目链接改为力扣中的对应题目,题目描述和代码按该题的接口调整。 --- notes/4. 二维数组中的查找.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/notes/4. 二维数组中的查找.md b/notes/4. 二维数组中的查找.md index 62281154..6d8ae40e 100644 --- a/notes/4. 二维数组中的查找.md +++ b/notes/4. 二维数组中的查找.md @@ -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.

```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--;