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