36. Valid Sudoku
Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 62% Topics: Array, Hash Table, Matrix
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
class Solution:
def isValidSudoku(self, board: List[List[str]]) -> bool:
seen = set()
for i in range(9):
for j in range(9):
if board[i][j] != ".":
num = board[i][j]
if (
(i, num) in seen
or (num, j) in seen
or (i // 3, j // 3, num) in seen
):
return False
seen.add((i, num))
seen.add((num, j))
seen.add((i // 3, j // 3, num))
return True
Solution from kamyu104/LeetCode-Solutions · MIT
Similar questions