Issue With Code : PYTHON


#1
class Solution:
    # @param A : list of list of chars
    # @return nothing
    def can_put_num(self,i,j,A,num):
        for k in range(9):
            if A[i][k]==str(num) or A[k][j]==str(num):
                return False
        block_x=i//3
        block_y=j//3
        for a in range(block_x*3,block_x*3+3):
            for b in range(block_y*3,block_y*3+3):
                if A[a][b]==str(num):
                    return False
        return True
    def sudoku_solver(self,i,j,A):
        if i==9:
            return True
        if j==9:
            return self.sudoku_solver(i+1,0,A)
        if A[i][j]!=".":
            return self.sudoku_solver(i,j+1,A)       
        for num in range(1,10):
            # print(i,j,num)
            if self.can_put_num(i,j,A,num):
                A[i][j]=str(num)
                if self.sudoku_solver(i,j+1,A):
                    return True
                A[i][j]="."
        # return False
    def solveSudoku(self, A):
        A=[list(i[0]) for i in A]
        self.sudoku_solver(0,0,A)
        A=["".join(A[i]) for i in range(len(A))]Comment body goes here.