Skip to content

Commit 9be5205

Browse files
Create Search-a-2d-matrix.java
1 parent c5943dc commit 9be5205

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Java/Search-a-2d-matrix.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class Solution {
2+
public boolean searchMatrix(int[][] matrix, int target) {
3+
4+
if(matrix.length == 0 || matrix[0].length == 0){
5+
return false;
6+
}
7+
8+
if(matrix[matrix.length-1][matrix[0].length-1] < target){
9+
return false;
10+
}
11+
12+
for(int i=0; i<matrix.length; i++){
13+
for(int j=0; j<matrix[i].length; j++){
14+
15+
if(matrix[i][j] > target){
16+
return false;
17+
}
18+
else if(matrix[i][j] == target){
19+
return true;
20+
}
21+
else{
22+
continue;
23+
}
24+
}
25+
}
26+
27+
return false;
28+
}
29+
}

0 commit comments

Comments
 (0)