classSolution:defsolveSudoku(self,board: List[List[str]]) ->None:""" Do not return anything, modify board in-place instead. """ self.board = board self.solve()deffind_uassigned(self):for row inrange(9):for col inrange(9):if self.board[row][col] =='.':return row, colreturn-1,-1defsolve(self): row, col = self.find_uassigned()# no dot in board, all solvedif (row, col) == (-1,-1):returnTrue# backtracking every number, in every possible positionfor num in ['1','2','3','4','5','6','7','8','9']:if self.is_safe(row, col, num): self.board[row][col] = numif self.solve():returnTrue self.board[row][col] ='.'returnFalsedefis_safe(self,row,col,ch):# left-top index of every square boxrow = row - row %3 boxcol = col - col %3if self.check_row(row, ch)and self.check_col(col, ch)and self.check_square(boxrow, boxcol, ch):returnTruereturnFalsedefcheck_row(self,row,ch):for col inrange(9):if self.board[row][col] == ch:returnFalsereturnTruedefcheck_col(self,col,ch):for row inrange(9):if self.board[row][col] == ch:returnFalsereturnTruedefcheck_square(self,row,col,ch):for r inrange(row, row+3):for c inrange(col, col+3):if self.board[r][c] == ch:returnFalsereturnTrue