-
Notifications
You must be signed in to change notification settings - Fork 0
/
036.cpp
46 lines (45 loc) · 962 Bytes
/
036.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
class Solution {
public:
bool isValidSudoku(vector<vector<char>>& board) {
bool ans=true;
ans = ans & line(0,1,board);
ans = ans & line(1,0,board);
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
ans = ans&cube(i*3,j*3,board);
}
}
return ans;
}
bool line(int x,int y,vector<vector<char>>& board){
for(int i=0;i<9;i++){
map<char,int> mao;
for(int j=0;j<9;j++){
int nx=(x==0?i:j);
int ny=(x==0?j:i);
char ch=board[nx][ny];
if(ch!='.') mao[ch]++;
if(mao[ch]>1) return false;
}
}
return true;
}
bool cube(int x,int y,vector<vector<char>>& board){
map<char,int> san;
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
int nx=x+i;
int ny=y+j;//bug
char ch=board[nx][ny];
if(ch!='.') san[ch]++;
if(san[board[nx][ny]]>1) return false;
}
}
return true;
}
};
/*
- mix char and int type; and ignore the amount of '.' is large
- j mistake of i;
- logic is clear, then debug is easy.
*/