class Solution {
public:
bool isValidSudoku(vector<vector<char>>& board) {
// brust way
int a[9][9];
for(int i=0;i<9;i++) {
for(int j=0;j<9;j++) {
a[i][j] = board[i][j] == '.' ? - 1 : board[i][j] - '0';
}
}
int b[10][10], c[10][10];
int d[3][3][10];
for(int i=0;i<10;i++) {
for(int j=0;j<10;j++) {
b[i][j] = 0;
c[i][j] = 0;
}
}
for(int i=0;i<3;i++) {
for(int j=0;j<3;j++) {
for(int k=0;k<10;k++) {
d[i][j][k] = 0;
}
}
}
for(int i=0;i<9;i++) {
for(int j=0;j<9;j++) {
if(a[i][j] != -1) {
b[i][a[i][j]]++;
if(b[i][a[i][j]] > 1) return false;
c[j][a[i][j]]++;
if(c[j][a[i][j]] > 1) return false;
d[i/3][j/3][a[i][j]]++;
if(d[i/3][j/3][a[i][j]] > 1) return false;
}
}
}
return true;
}
};
Reactions are currently unavailable
class Solution { public: bool isValidSudoku(vector<vector<char>>& board) { // brust way int a[9][9]; for(int i=0;i<9;i++) { for(int j=0;j<9;j++) { a[i][j] = board[i][j] == '.' ? - 1 : board[i][j] - '0'; } } int b[10][10], c[10][10]; int d[3][3][10]; for(int i=0;i<10;i++) { for(int j=0;j<10;j++) { b[i][j] = 0; c[i][j] = 0; } } for(int i=0;i<3;i++) { for(int j=0;j<3;j++) { for(int k=0;k<10;k++) { d[i][j][k] = 0; } } } for(int i=0;i<9;i++) { for(int j=0;j<9;j++) { if(a[i][j] != -1) { b[i][a[i][j]]++; if(b[i][a[i][j]] > 1) return false; c[j][a[i][j]]++; if(c[j][a[i][j]] > 1) return false; d[i/3][j/3][a[i][j]]++; if(d[i/3][j/3][a[i][j]] > 1) return false; } } } return true; } };