Loading...
You are given a two-dimensional integer array matrix. Determine whether it is a Toeplitz matrix: a matrix where every diagonal running from the top-left toward the bottom-right holds the same value all the way along.
Concretely, for every cell matrix[i][j] that has a cell below and to the right of it, matrix[i][j] must equal matrix[i + 1][j + 1].
Note that a matrix with a single row or a single column is always a Toeplitz matrix, since none of its cells have a diagonal neighbor to compare against.
Return whether matrix is a Toeplitz matrix.
Input: matrix = [[1,2,3,4],[5,1,2,3],[9,5,1,2]]
Output: true
Input: matrix = [[1,2],[2,2]]
Output: false
Input: matrix = [[7]]
Output: true
matrix.lengthmatrix[0].lengthmatrix[i][j] ≤109Click "Run" to test with sample cases or "Submit" to run all tests.