classSolution: defisValidSudoku(self, board: List[List[str]]) -> bool: return (self.roww(board) and self.coll(board) and self.square(board)) defunitt(self, unit): unit = [elem for elem in unit if elem !="."] return len(set(unit)) == len(unit) defroww(self, board): for row in board: ifnot self.unitt(row): returnFalse returnTrue
defcoll(self, board): for col in zip(*board): ifnot self.unitt(col): returnFalse returnTrue
defsquare(self, board): for i in (0, 3, 6): for j in (0, 3, 6): square = [board[x][y] for x in range(i, i+3) for y in range(j, j+3)] ifnot self.unitt(square): returnFalse returnTrue