Skip to content

Commit 191d3dc

Browse files
74. Search a 2D Matrix (java)
1 parent 0200300 commit 191d3dc

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public boolean searchMatrix(int[][] matrix, int target) {
3+
int x = 0,y = matrix.length-1;
4+
if(y<0) return false;
5+
int maxX = matrix[0].length-1;
6+
while ((x <= maxX) && (y >= 0)) {
7+
int cur = matrix[y][x];
8+
if (cur == target) return false;
9+
if (cur < target) x++;
10+
else y--;
11+
}
12+
return false;
13+
}
14+
}

0 commit comments

Comments
 (0)