LC 0766 [E] Toeplitz Matrix - ALawliet/algorithms GitHub Wiki
A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same elements.
class Solution:
def isToeplitzMatrix(self, matrix: List[List[int]]) -> bool:
ROWS = len(matrix)
COLS = len(matrix[0])
for r in range(ROWS):
for c in range(COLS):
nr, nc = r + 1, c + 1 # next diag
if 0 <= nr < ROWS and 0 <= nc < COLS:
if matrix[nr][nc] != matrix[r][c]:
return False
return True