My c++ solution simple to understand but need improvements


#1

Please help me optimize and improve this code i am sure it will increasing your understanding in reading the code as well

 indent preformatted text by 4 spaces

int Solution::isValidSudoku(const vector &A) {
unordered_map<char, int> col;
unordered_map<char, int> row;
unordered_map<char, int> block;
for(int i = 0 ; i < 9 ; i++){
string x = A[i];
for(int j = 0; j<9; j++){
if(x[j]==’.’){continue;}
else{
row[x[j]]++;
if(row[x[j]]>1){return 0;}
}
}
row.clear();
}
for(int i = 0; i<9 ; i++){
for(int j = 0; j<9; j++){
string x = A[j];
if(x[i] == ‘.’){continue;}
else{
col[x[i]]++;
if(col[x[i]]>1){return 0;}
}
}
col.clear();
}
for(int i = 0; i<9; i+=3){
for(int j = 0; j<9 ; j+=3){
string x = A[i];
string y = A[i+1];
string z = A[i+2];
block[x[j]]++;
block[x[j+1]]++;
block[x[j+2]]++;
block[y[j]]++;
block[y[j+1]]++;
block[y[j+2]]++;
block[z[j]]++;
block[z[j+1]]++;
block[z[j+2]]++;
for(auto it = block.begin(); it!=block.end(); it++){
if(it->first!=’.’ &&it->second>1){return 0;}
}
block.clear();A
}
}
return 1;

}