Here's my c++ solution


#1

bool isvalid(int i,int j,int x,vector<vector > &A){
char X = x + ‘0’;
for(int t = 0;t<A.size();t++){
if(X == A[i][t])return false;
}
for(int t = 0;t<A.size();t++){
if(X == A[t][j])return false;
}
int I,J;
I = i%3;
J = j%3;
for(int t = i-I;t<3+i-I;t++){
for(int t1 = j-J;t1<3+j-J;t1++){
if(X == A[t][t1])return false;

    }
}
return true;

}

bool canfill(vector<vector > &A){
for(int i= 0;i<A.size();i++){
for(int j = 0;j<A.size();j++){
if(A[i][j]==’.’)return true;
}
}
return false;
}

bool isempty(vector<vector > &A,int i,int j){
if(A[i][j]==’.’)return true;
return false;
}

void recur(vector<vector > &A,int i,int j){
if(!canfill(A))return;
if(!isempty(A,i,j)){
if(i == 8){
if( j == 8)recur(A,0,0);
else recur(A,0,j+1);
}
else recur(A,i+1,j);
return;

}
for(int N = 1;N<=9;N++){
    if(isvalid(i,j,N,A)){
        A[i][j] = N+'0';
        if(i == 8){
            if( j == 8)recur(A,0,0);
            else recur(A,0,j+1);
        }
        else recur(A,i+1,j);
        if(!canfill(A))return;
        else A[i][j] = '.';
        
    }
}
return;

}

void Solution::solveSudoku(vector<vector > &A) {
recur(A,0,0);
return;
}


#2

can you provide the time complexity?