-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSolution.java
More file actions
40 lines (38 loc) · 1.04 KB
/
Solution.java
File metadata and controls
40 lines (38 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package $074;
/**
* @author Junlan Shuai[shuaijunlan@gmail.com].
* @date Created on 9:27 AM 2018/07/25.
*/
public class Solution {
public boolean searchMatrix(int[][] matrix, int target) {
if (matrix == null || matrix.length == 0){
return false;
}
if (matrix.length == 1){
for (int m = 0; m < matrix[0].length; m++){
if (matrix[0][m] == target){
return true;
}
}
return false;
}
int i = 0, j = 1;
while (j < matrix.length){
if (target >= matrix[i][0] && target < matrix[j][0]){
for (int m = 0; m < matrix[0].length; m++){
if (matrix[i][m] == target){
return true;
}
}
}
i++;
j++;
}
for (int m = 0; m < matrix[0].length; m++){
if (matrix[j-1][m] == target){
return true;
}
}
return false;
}
}