C++ solution valid sudoku

programming
interview-questions
Tags: #<Tag:0x00007f2428d03290> #<Tag:0x00007f2428d03150>

#1

int Solution::isValidSudoku(const vector &A) {
vector<vector>row(9,vector(9,0));
vector<vector>col(9,vector(9,0));
vector<vector>box(9,vector(9,0));
for(int i=0;i<9;i++){
for(int j=0;j<9;j++){
if(A[i][j]!=’.’){
int num=A[i][j]-‘1’;
int k=(i/3)*3 + j/3;
if(row[num][j]++ || col[i][num]++ || box[k][num]++) //check if element is not repeating
return 0;
}
}
}
return 1;
}