Description
Given an m x n matrix, return true if the matrix is Toeplitz. A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same elements.
Examples
Input:
matrix = [[1,2,3,4],[5,1,2,3],[9,5,1,2]]Output:
trueExplanation:
All diagonals same.
Input:
matrix = [[1,2],[2,2]]Output:
falseExplanation:
The diagonal from (0,0) has value 1, but (1,1) has value 2. For a Toeplitz matrix, all diagonals must have equal values.
Input:
matrix = [[7,8,9],[4,7,8],[1,4,7]]Output:
trueExplanation:
Each diagonal has identical elements: top-left to bottom-right diagonals contain [9], [8,8], [7,7,7], [4,4], and [1] respectively.
Constraints
- •
1 ≤ m, n ≤ 20