> For the complete documentation index, see [llms.txt](https://r24zeng.gitbook.io/leetcode-notebook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://r24zeng.gitbook.io/leetcode-notebook/zhong-yu-shua-dao-100-dao-le-wo-shi-fen-shui-ling/bu-chong-120-dao/36.-valid-sudoku.md).

# 36. Valid Sudoku

\# Medium

{% hint style="info" %}
Easy
{% endhint %}

### Solution:

1. Judge repeatition in horizon.
2. Judge repeatition in vertical.
3. Judge repeatition in 3x3 blocks.

{% tabs %}
{% tab title="Python" %}

```python
class Solution(object):
    def isValidSudoku(self, board):
        """
        :type board: List[List[str]]
        :rtype: bool
        """

        # vertical
        for i in range(9):
            if self.vertical(board, i) == False:
                return False
        
        # horizontal
        for i in range(9):
            if self.horizon(board, i) == False:
                return False
            
        # blocks
        for i in range(3):
            for j in range(3):
                if self.block(board, i, j) == False:
                    return False
        
        return True
    
    def vertical(self, board, i):
        temp = []
        for x in range(9):
            if board[x][i] != '.':
                if board[x][i] in temp:
                    return False
                else:
                    temp.append(board[x][i])
        return True
        
    def horizon(self, board, i):
        temp = []
        for x in range(9):
            if board[i][x] != '.':
                if board[i][x] in temp:
                    return False
                else:
                    temp.append(board[i][x])
        return True
    
    def block(self, board, i, j):
        #print(sub)
        temp = []
        for x in range(i*3, (i+1)*3):
            for y in range(j*3, (j+1)*3):
                if board[x][y] != '.':
                    if board[x][y] in temp:
                        return False
                    else:
                        temp.append(board[x][y])
        return True
```

{% endtab %}
{% endtabs %}

{% hint style="danger" %}
`list[x]` represents **`xth`** row in Python.

`list[:][x]` doesn't represent **`xth`** column in Python.
{% endhint %}
