Simple HashTable solution


#1

int Solution::isValidSudoku(const vector &A) {
map<string,int> mp;
for(int i=0;i<9;i++){
for(int j=0;j<9;j++){
if(A[i][j] !=’.’){
string str1 = “”,str2="",str3="";
str1 += to_string(A[i][j]) + " found in row " + to_string(i);
str2 += to_string(A[i][j]) + " found in column " + to_string(j);
str3 += to_string(A[i][j]) + " found in subbox " + to_string(i/3)+ " " + to_string(j/3);
if(mp.find(str1) != mp.end() || mp.find(str2) != mp.end() || mp.find(str3) != mp.end())
return 0;
else{
mp.insert(make_pair(str1,1));
mp.insert(make_pair(str2,1));
mp.insert(make_pair(str3,1));
}
}

 }
}
return 1;

}