---
# System prepended metadata

title: Leetcode 766. Toeplize Matrix

---

# Leetcode 766. Toeplize Matrix

## 左上驗證法


每次驗證左上方的對角線區塊，如果數字不一致，回傳 False

```python=
class Solution:
    def isToeplitzMatrix(self, matrix: List[List[int]]) -> bool:
        xc, yc = len(matrix[0]), len(matrix)

        for y in range(yc):
            for x in range(xc):
                if x >= 1 and y >= 1:
                    check_cell = matrix[y-1][x-1]
                    if check_cell != matrix[y][x]:
                        return False
        return True
```

2023.10.02 AC

```python!
class Solution:
    def isToeplitzMatrix(self, matrix: List[List[int]]) -> bool:
        m,n = len(matrix),len(matrix[0])

        for y in range(m):
            for x in range(n):
                if y >= 1 and x >= 1 and matrix[y-1][x-1] != matrix[y][x]:
                    return False
        
        return True
```