class Solution:
def isValidSudoku(self, board: List[List[str]]) -> bool:
rows = [set() for i in range(9)]
columns = [set() for i in range(9)]
sub_box = [[set(),set(),set()],[set(),set(),set()],[set(),set(),set()]]
for i in range(9) :
for j in range(9):
num = board[i][j]
if num == "." : continue
if num in rows[i] : return False
if num in columns[j] : return False
if num in sub_box[i//3][j//3] : return False
rows[i].add(num)
columns[j].add(num)
sub_box[i//3][j//3].add(num)
return True
문제정리
Determind if sudoku board is valid.
풀이과정
Store the numbers from each row, column, and 3x3 sub-box in separate hash sets. Iterate through each cell in the Sudoku and check whether the current number already exists in its correcsponding row, column, or sub-box. If it does, return False; otherwise, add th number to each hash set.
풀이 후
Nothing.