image_2022-08-21_00-30-41.png
40.9 KB
#N2133. Check if Every Row and Column Contains All Numbers
problem link
#solution
problem link
#solution
class Solution {
public boolean checkValid(int[][] matrix) {
int n=matrix.length;
Set<Integer> set1 = new HashSet<>();
Set<Integer> set2 = new HashSet<>();
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(!set1.add(matrix[i][j]) || !set2.add(matrix[j][i])) return false;
}
set1 = new HashSet<>();
set2 = new HashSet<>();
}
return true;
}
}