#766

Toeplitz Matrix

newbie · 285 · lc easy +20 · verified · 69.6% accepted · 3,720 likes · top 78%

Description

An m x n matrix is Toeplitz if all elements along each top-left-to-bottom-right diagonal are identical. Given such a matrix, return true if it is Toeplitz, or false otherwise.

Example 1:

Input: matrix = [[1,2,3,4],[5,1,2,3],[9,5,1,2]]
Output: true
Explanation:
In the above grid, the diagonals are:
"[9]", "[5, 5]", "[1, 1, 1]", "[2, 2, 2]", "[3, 3]", "[4]".
In each diagonal all elements are the same, so the answer is True.

Example 2:

Input: matrix = [[1,2],[2,2]]
Output: false
Explanation:
The diagonal "[1, 2]" has different elements.

Code

1
2
3