-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleetcode2133.java
More file actions
44 lines (36 loc) · 1.13 KB
/
Copy pathleetcode2133.java
File metadata and controls
44 lines (36 loc) · 1.13 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
41
42
43
44
package Java8;
import java.util.HashSet;
import java.util.Set;
public class leetcode2133 {
public boolean checkValid(int[][] matrix) {
int n = matrix.length;
Set<Integer> hashSet = new HashSet<>();
Set<Integer> hashSetTemp = new HashSet<>();
for (int k = 1; k <= n; k++) {
hashSet.add(k);
}
for (int j = 0; j < n; j++) {
hashSetTemp.addAll(hashSet);
for (int m = 0; m < n; m++) {
hashSetTemp.remove(matrix[j][m]);
}
if (hashSetTemp.size() != 0)
return false;
}
for (int p = 0; p < n; p++) {
hashSetTemp.addAll(hashSet);
for (int s = 0; s < n; s++) {
hashSetTemp.remove(matrix[s][p]);
}
if (hashSetTemp.size() != 0)
return false;
}
return true;
}
public static void main(String[] args) {
leetcode2133 obj = new leetcode2133();
int[][] matrix = {{1, 1, 1}, {1, 2, 3}, {1, 2, 3}};
boolean ans = obj.checkValid(matrix);
System.out.println(ans);
}
}