mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 19:53:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			43 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			43 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<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> </p>
 | 
						|
<p><strong class="example">Example 1:</strong></p>
 | 
						|
<img alt="" src="https://assets.leetcode.com/uploads/2020/11/04/ex1.jpg" style="width: 322px; height: 242px;" />
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> matrix = [[1,2,3,4],[5,1,2,3],[9,5,1,2]]
 | 
						|
<strong>Output:</strong> true
 | 
						|
<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.
 | 
						|
</pre>
 | 
						|
 | 
						|
<p><strong class="example">Example 2:</strong></p>
 | 
						|
<img alt="" src="https://assets.leetcode.com/uploads/2020/11/04/ex2.jpg" style="width: 162px; height: 162px;" />
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> matrix = [[1,2],[2,2]]
 | 
						|
<strong>Output:</strong> false
 | 
						|
<strong>Explanation:</strong>
 | 
						|
The diagonal "[1, 2]" has different elements.
 | 
						|
</pre>
 | 
						|
 | 
						|
<p> </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> </p>
 | 
						|
<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>
 |