Created
April 5, 2026 05:58
-
-
Save ksamirdev/4e42920b2e3d64c90fc3508686d92361 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution: | |
| def isValidSudoku(self, board: List[List[str]]) -> bool: | |
| rows = collections.defaultdict(set) | |
| cols = collections.defaultdict(set) | |
| boxes = collections.defaultdict(set) | |
| for r in range(9): | |
| for c in range(9): | |
| if board[r][c] == '.': | |
| continue | |
| if (board[r][c] in rows[r] or | |
| board[r][c] in cols[c] or | |
| board[r][c] in boxes[r//3, c//3]): | |
| return False | |
| rows[r].add(board[r][c]) | |
| cols[c].add(board[r][c]) | |
| boxes[r//3,c//3].add(board[r][c]) | |
| return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment