---
# System prepended metadata

title: Valid sudoku
tags: [data_structure_python]

---

---
tags: data_structure_python
---

# Valid sudoku

https://leetcode.com/problems/valid-sudoku/

```python=
class Solution:
    def isValidSudoku(self, board: List[List[str]]) -> bool:
        
        n = len(board)
        
        rows  = {i:[] for i in range(n)}
        cols  = {i:[] for i in range(n)} 
        boxes = {i:[] for i in range(n)}
        
        for i in range(n):
            for j in range(n):
                
                if board[i][j] == ".":
                    continue
                
                if board[i][j] in rows[i] or board[i][j] in cols[j] or board[i][j] in boxes[3*(i//3) + j//3]:
                    return False
                
                rows[i] += [board[i][j]]
                cols[j] += [board[i][j]]
                boxes[3*(i//3) + j//3] += [board[i][j]]

                    
        return True
```