-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path36_ValidSudoku
107 lines (107 loc) · 3.68 KB
/
36_ValidSudoku
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
bool isValidSudoku(vector<vector<char>>& board) {
unordered_set<int>
map,map2,map3,map4,map5,map6,map7,map8,map9;
for(int i=0; i<9; i++){
for(int j=0; j<9; j++){
if(board[i][j]=='.')
continue;
if(map.count(board[i][j]))
return false;
else
map.insert(board[i][j]);
}
map.clear();
}
map.clear();
for(int i=0; i<9; i++){
for(int j=0; j<9; j++){
if(board[j][i]=='.')
continue;
if(map.count(board[j][i]))
return false;
else
map.insert(board[j][i]);
}
map.clear();
}
map.clear();
for(int i=0; i<9; i++){
for(int j=0; j<9; j++){
if(i<=2 && j<=2){
if(board[i][j]=='.')
continue;
if(map.count(board[i][j]))
return false;
else
map.insert(board[i][j]);
}
if(i<=2 && (j>2 && j<6)){
if(board[i][j]=='.')
continue;
if(map2.count(board[i][j]))
return false;
else
map2.insert(board[i][j]);
}
if(i<=2 && (j>5 && j<9)){
if(board[i][j]=='.')
continue;
if(map3.count(board[i][j]))
return false;
else
map3.insert(board[i][j]);
}
if((i>2 && i<6) && j<=2){
if(board[i][j]=='.')
continue;
if(map4.count(board[i][j]))
return false;
else
map4.insert(board[i][j]);
}
if((i>2 && i<6) && (j>2 && j<6)){
if(board[i][j]=='.')
continue;
if(map5.count(board[i][j]))
return false;
else
map5.insert(board[i][j]);
}
if((i>2 && i<6) && (j>5 && j<9)){
if(board[i][j]=='.')
continue;
if(map6.count(board[i][j]))
return false;
else
map6.insert(board[i][j]);
}
if((i>5 && i<9) && j<=2){
if(board[i][j]=='.')
continue;
if(map7.count(board[i][j]))
return false;
else
map7.insert(board[i][j]);
}
if((i>5 && i<9) && (j>2 && j<6)){
if(board[i][j]=='.')
continue;
if(map8.count(board[i][j]))
return false;
else
map8.insert(board[i][j]);
}
if((i>5 && i<9) && (j>5 && j<9)){
if(board[i][j]=='.')
continue;
if(map9.count(board[i][j]))
return false;
else
map9.insert(board[i][j]);
}
}
}
map2.clear(); map3.clear(); map4.clear(); map5.clear();
map6.clear(); map7.clear(); map8.clear(); map9.clear();
return true;
}