Skip to content

Instantly share code, notes, and snippets.

@ksamirdev
Created April 5, 2026 05:58
Show Gist options
  • Select an option

  • Save ksamirdev/4e42920b2e3d64c90fc3508686d92361 to your computer and use it in GitHub Desktop.

Select an option

Save ksamirdev/4e42920b2e3d64c90fc3508686d92361 to your computer and use it in GitHub Desktop.
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