Skip to content

Commit 39d5b2f

Browse files
committed
Time: 41 ms (65.20%), Space: 22.3 MB (5.26%) - LeetHub
1 parent 875d024 commit 39d5b2f

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)