We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 875d024 commit 39d5b2fCopy full SHA for 39d5b2f
0036-valid-sudoku/0036-valid-sudoku.cpp
@@ -0,0 +1,28 @@
1
+class Solution {
2
+public:
3
+ bool isValidSudoku(vector<vector<char>>& b) {
4
+ unordered_set<string>st;
5
+
6
+ for(int i = 0 ; i < b.size() ; i++){
7
+ for(int j = 0 ; j < b[0].size() ; j++){
8
+ if(b[i][j] != '.'){
9
+ int boxNum = (i/3)*3+(j/3);
10
+ string row = to_string(b[i][j]) + " found at row " + to_string(i);
11
+ string col = to_string(b[i][j]) + " found at col " + to_string(j);
12
+ string box = to_string(b[i][j]) + " found at box " + to_string(boxNum);
13
14
+ if(st.find(row)!=st.end() || st.find(col) != st.end() || st.find(box) != st.end()){
15
+ return false;
16
+ }
17
+ else{
18
+ st.insert(row);
19
+ st.insert(col);
20
+ st.insert(box);
21
22
23
24
25
26
+ return true;
27
28
+};
0 commit comments