mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-10 18:01:41 +08:00
update
This commit is contained in:
44
leetcode/problem/matrix-similarity-after-cyclic-shifts.html
Normal file
44
leetcode/problem/matrix-similarity-after-cyclic-shifts.html
Normal file
@@ -0,0 +1,44 @@
|
||||
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> integer matrix <code>mat</code> and an integer <code>k</code>. You have to cyclically <strong>right</strong> shift <strong>odd</strong> indexed rows <code>k</code> times and cyclically <strong>left</strong> shift <strong>even</strong> indexed rows <code>k</code> times.</p>
|
||||
|
||||
<p>Return <code>true</code> <em>if the initial and final matrix are exactly the same and </em><code>false</code> <em>otherwise.</em></p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> mat = [[1,2,1,2],[5,5,5,5],[6,3,6,3]], k = 2
|
||||
<strong>Output:</strong> true
|
||||
<strong>Explanation:</strong>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2023/10/29/similarmatrix.png" style="width: 500px; height: 117px;" />
|
||||
|
||||
Initially, the matrix looks like the first figure.
|
||||
Second figure represents the state of the matrix after one right and left cyclic shifts to even and odd indexed rows.
|
||||
Third figure is the final state of the matrix after two cyclic shifts which is similar to the initial matrix.
|
||||
Therefore, return true.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> mat = [[2,2],[2,2]], k = 3
|
||||
<strong>Output:</strong> true
|
||||
<strong>Explanation:</strong> As all the values are equal in the matrix, even after performing cyclic shifts the matrix will remain the same. Therefeore, we return true.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> mat = [[1,2]], k = 1
|
||||
<strong>Output:</strong> false
|
||||
<strong>Explanation:</strong> After one cyclic shift, mat = [[2,1]] which is not equal to the initial matrix. Therefore we return false.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= mat.length <= 25</code></li>
|
||||
<li><code>1 <= mat[i].length <= 25</code></li>
|
||||
<li><code>1 <= mat[i][j] <= 25</code></li>
|
||||
<li><code>1 <= k <= 50</code></li>
|
||||
</ul>
|
Reference in New Issue
Block a user