From 1b2272abe0964bbbd244f0c57e5d2b696d6502a3 Mon Sep 17 00:00:00 2001 From: Omooo <869759698@qq.com> Date: Tue, 9 Jun 2020 08:55:06 +0800 Subject: [PATCH] =?UTF-8?q?Create=20=E6=95=B0=E7=BB=84=E7=9B=B8=E5=85=B3.m?= =?UTF-8?q?d?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blogs/Algorithm/剑指 Offer/数组相关.md | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 blogs/Algorithm/剑指 Offer/数组相关.md diff --git a/blogs/Algorithm/剑指 Offer/数组相关.md b/blogs/Algorithm/剑指 Offer/数组相关.md new file mode 100644 index 0000000..ef795ba --- /dev/null +++ b/blogs/Algorithm/剑指 Offer/数组相关.md @@ -0,0 +1,29 @@ +--- +数组相关 +--- + +[04. 二维数组中的查找](https://leetcode-cn.com/problems/er-wei-shu-zu-zhong-de-cha-zhao-lcof/) + +```java +class Solution { + + public boolean findNumberIn2DArray(int[][] matrix, int target) { + if (matrix == null || matrix.length == 0) { + return false; + } + int m = matrix.length, n = matrix[0].length; + int row = 0, col = n - 1; + while (row < m && col >= 0) { + if (matrix[row][col] > target) { + col--; + } else if (matrix[row][col] < target) { + row++; + } else { + return true; + } + } + return false; + } +} +``` +