-
Notifications
You must be signed in to change notification settings - Fork 0
LC 0766 [E] Toeplitz Matrix
Code with Senpai edited this page Aug 4, 2022
·
4 revisions
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
footer