Problem statement

https://binarysearch.com/problems/Toeplitz-Matrix/

Solution

Equal to Leetcode 0766 Toeplitz Matrix.

Complexity

It is O(mn) for time and space.

Code

class Solution:
    def solve(self, matrix):
        m, n = len(matrix), len(matrix[0])
        row = matrix[0]
        for i in range(1, m):
            if matrix[i][1:] != row[:-1]: return False
            row = matrix[i]
        return True