Check if Every Row and Column Contains All Numbers LeetCode solution in C++

1
class Solution {
2
public:
3
bool checkValid(vector<vector<int>> &matrix) {
4
int n = matrix.size();
5
unordered_set<int> s1, s2;
6
for (int i = 0; i < n; i++) {
7
for (int j = 0; j < n; j++) {
8
if (s1.find(matrix[i][j]) != s1.end())
9
return false;
10
else
11
s1.insert(matrix[i][j]);
12
if (s2.find(matrix[j][i]) != s2.end())
13
return false;
14
else
15
s2.insert(matrix[j][i]);
16
}
17
s1.clear();
18
s2.clear();
19
}
20
return true;
21
}
22
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0