Create 数组相关.md

master
Omooo 5 years ago
parent 2fd4fe195e
commit 1b2272abe0
  1. 29
      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;
}
}
```
Loading…
Cancel
Save