forked from DengWangBao/Leetcode-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearch2DMatrixII.java
More file actions
23 lines (19 loc) · 538 Bytes
/
Search2DMatrixII.java
File metadata and controls
23 lines (19 loc) · 538 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public class Search2DMatrixII {
// 耗时14ms
public boolean searchMatrix(int[][] matrix, int target) {
if (matrix.length == 0) {
return false;
}
int row = matrix.length, col = matrix[0].length;
for (int i = 0, j = col - 1; i < row && j >= 0; ) {
if (target > matrix[i][j]) {
i++;
} else if (target < matrix[i][j]) {
j--;
} else {
return true;
}
}
return false;
}
}