Advertisement
Guest User

Valid Sudoku

a guest
Feb 23rd, 2021
76
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ```python
  2. def isValidSudoku(self, board: List[List[str]]) -> bool:
  3. rows = [set() for i in range(9)]
  4. cols = [set() for i in range(9)]
  5. squares = [[set() for i in range(3)] for i in range(3)]
  6.  
  7. for i in range(len(board)):
  8. for j in range(len(board[i])):
  9. if board[i][j] == ".":
  10. continue
  11. if board[i][j] in cols[j]:
  12. return False
  13. else:
  14. cols[j].add(board[i][j])
  15.  
  16. if board[i][j] in rows[i]:
  17. return False
  18. else:
  19. rows[i].add(board[i][j])
  20.  
  21. if board[i][j] in squares[i // 3][j // 3]:
  22. return False
  23. else:
  24. squares[i // 3][j // 3].add(board[i][j])
  25.  
  26. return True
  27. ```
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement