Simple C++ solution with only one map


#1

int Solution::isValidSudoku(const vector &A) {

unordered_set <string> s;
for(int i=0; i<9;i++)
{
    for(int j=0; j<9;j++)
    {
        char c = char(A[i][j]);
        if(c == '.')
            continue;

        string str1 = to_string(c-'0')+"inserted in "+to_string(i)+"row";
        string str2 = to_string(c-'0')+"inserted in "+to_string(j)+"column";
        string str3 = to_string(c-'0')+"inserted in "+c+to_string(i/3)+"-"+to_string(j/3)+"block";

        
        if( s.find(str1) != s.end() || s.find(str2)!= s.end() || s.find(str3) != s.end() )
            return 0;
        else
        {
                 s.insert(str1);  
                 s.insert(str2);
                 s.insert(str3);
                
        }
    }
    
}
return 1;

}