Without using extra space c++


#1
indent preformatted text by 4 spaces

int Solution::isValidSudoku(const vector &A) {
int i,j;
for(i=0;i<9;i++){
set s;
for(j=0;j<9;j++){
if( A[i][j] != ‘.’ && !s.count(A[i][j]) )
s.insert(A[i][j]);
else if(A[i][j] != ‘.’ && s.count(A[i][j]))
return 0;
}
}
for(i=0;i<9;i++){
set s;
for(j=0;j<9;j++){
if( A[j][i] != ‘.’ && !s.count(A[j][i]))
s.insert(A[j][i]);
else if(A[j][i] != ‘.’ && s.count(A[j][i]))
return 0;
}
}
for(int i = 0; i < 9; i = i + 3) {
for(int j = 0; j < 9; j = j + 3) {
set s;
for(int k = i; k < i + 3 ; k++) {
for(int l = j; l < j + 3; l++) {
if(A[k][l] != ‘.’ && !s.count(A[k][l]))
s.insert(A[k][l]);
else if(A[k][l] != ‘.’ && s.count(A[k][l]))
return 0;
}
}
}
}
return 1;
}