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