Package g0701_0800.s0766_toeplitz_matrix
Class Solution
java.lang.Object
g0701_0800.s0766_toeplitz_matrix.Solution
766 - Toeplitz Matrix.<p>Easy</p>
<p>Given an <code>m x n</code> <code>matrix</code>, return <em><code>true</code> if the matrix is Toeplitz. Otherwise, return <code>false</code>.</em></p>
<p>A matrix is <strong>Toeplitz</strong> if every diagonal from top-left to bottom-right has the same elements.</p>
<p><strong>Example 1:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2020/11/04/ex1.jpg" alt="" /></p>
<p><strong>Input:</strong> matrix = [[1,2,3,4],[5,1,2,3],[9,5,1,2]]</p>
<p><strong>Output:</strong> true</p>
<p><strong>Explanation:</strong> 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.</p>
<p><strong>Example 2:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2020/11/04/ex2.jpg" alt="" /></p>
<p><strong>Input:</strong> matrix = [[1,2],[2,2]]</p>
<p><strong>Output:</strong> false</p>
<p><strong>Explanation:</strong> The diagonal “[1, 2]” has different elements.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>m == matrix.length</code></li>
<li><code>n == matrix[i].length</code></li>
<li><code>1 <= m, n <= 20</code></li>
<li><code>0 <= matrix[i][j] <= 99</code></li>
</ul>
<p><strong>Follow up:</strong></p>
<ul>
<li>What if the <code>matrix</code> is stored on disk, and the memory is limited such that you can only load at most one row of the matrix into the memory at once?</li>
<li>What if the <code>matrix</code> is so large that you can only load up a partial row into the memory at once?</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
isToeplitzMatrix
public boolean isToeplitzMatrix(int[][] matrix)
-