Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules:
Note:
class Solution:
def isValidSudoku(self, board: List[List[str]]) -> bool:
= [set() for _ in range(9)]
rows = [set() for _ in range(9)]
cols = [[set() for _ in range(3)] for _ in range(3)]
squares
for row in range(9):
for col in range(9):
= board[row][col]
num if num == ".":
continue
if num in rows[row] or num in cols[col] or num in squares[row // 3][col // 3]:
return False
rows[row].add(num)
cols[col].add(num)// 3][col // 3].add(num)
squares[row
return True