Check if Every Row and Column Contains All Numbers LeetCode solution in C++
1class Solution {2public:3bool checkValid(vector<vector<int>> &matrix) {4int n = matrix.size();5unordered_set<int> s1, s2;6for (int i = 0; i < n; i++) {7for (int j = 0; j < n; j++) {8if (s1.find(matrix[i][j]) != s1.end())9return false;10else11s1.insert(matrix[i][j]);12if (s2.find(matrix[j][i]) != s2.end())13return false;14else15s2.insert(matrix[j][i]);16}17s1.clear();18s2.clear();19}20return true;21}22};