【LeetCode 36】有效的数独
【题解】
就一傻逼模拟题【代码】
class Solution {
public:
bool isValidSudoku(vector<vector<char>>& board) {
bool bo[10];
for (int i = 0;i < 9;i++){
memset(bo,0,sizeof(bo));
for (int j = 0;j < 9;j++){
if (board[i][j]!='.'){
if (bo[board[i][j]-'0']) return false;
bo[board[i][j]-'0'] = 1;
}
}
}
for (int j = 0;j < 9;j++){
memset(bo,0,sizeof(bo));
for (int i = 0;i < 9;i++){
if (board[i][j]!='.'){
if (bo[board[i][j]-'0']) return false;
bo[board[i][j]-'0'] = true;
}
}
}
for (int x0 = 0;x0<9;x0+=3)
for (int y0 = 0;y0<9;y0+=3){
memset(bo,0,sizeof(bo));
for (int i = 0;i < 3;i++)
for (int j = 0;j < 3;j++)
{
if (board[x0+i][y0+j]!='.'){
if (bo[board[x0+i][y0+j]-'0']) return false;
bo[board[x0+i][y0+j]-'0'] = true;
}
}
}
return true;
}
};