forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_2133.java
33 lines (31 loc) · 985 Bytes
/
_2133.java
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
package com.fishercoder.solutions;
import java.util.HashSet;
import java.util.Set;
public class _2133 {
public static class Solution1 {
public boolean checkValid(int[][] matrix) {
int n = matrix.length;
Set<Integer> set = new HashSet<>();
for (int i = 1; i <= n; i++) {
set.add(i);
}
for (int i = 0; i < n; i++) {
Set<Integer> copy = new HashSet<>(set);
for (int j = 0; j < n; j++) {
if (!copy.remove(matrix[i][j])) {
return false;
}
}
}
for (int j = 0; j < n; j++) {
Set<Integer> copy = new HashSet<>(set);
for (int i = 0; i < n; i++) {
if (!copy.remove(matrix[i][j])) {
return false;
}
}
}
return true;
}
}
}