-
Notifications
You must be signed in to change notification settings - Fork 1
/
Sudoku.cpp
55 lines (49 loc) · 1.36 KB
/
Sudoku.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
class Solution {
public:
bool isValidSudoku(vector<vector<char>>& board) {
for(int i=0;i<board.size();i++){
unordered_map<char,int> m;
for(int j=0;j<board[i].size();j++){
if(board[i][j]!='.'){
m[board[i][j]]++;
}
}
for(auto value:m){
if(value.second>1){
return false;
}
}
}
for(int i=0;i<board.size();i++){
unordered_map<char,int> m;
for(int j=0;j<board[i].size();j++){
if(board[j][i]!='.'){
m[board[j][i]]++;
}
}
for(auto value:m){
if(value.second>1){
return false;
}
}
}
for(int a=0;a!=board.size();a=a+3){
for(int b=0;b!=board.size();b=b+3){
unordered_map<char,int> m;
for(int i=a;i<a+3;i++){
for(int j=b;j<b+3;j++){
if(board[i][j]!='.'){
m[board[i][j]]++;
}
}
}
for(auto value:m){
if(value.second>1){
return false;
}
}
}
}
return true;
}
};