mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-05 15:31:43 +08:00
update
This commit is contained in:
39
leetcode/problem/cyclically-rotating-a-grid.html
Normal file
39
leetcode/problem/cyclically-rotating-a-grid.html
Normal file
@@ -0,0 +1,39 @@
|
||||
<p>You are given an <code>m x n</code> integer matrix <code>grid</code>, where <code>m</code> and <code>n</code> are both <strong>even</strong> integers, and an integer <code>k</code>.</p>
|
||||
|
||||
|
||||
|
||||
<p>The matrix is composed of several layers, which is shown in the below image, where each color is its own layer:</p>
|
||||
|
||||
|
||||
|
||||
<p><img alt="" src="https://assets.leetcode.com/uploads/2021/06/10/ringofgrid.png" style="width: 231px; height: 258px;" /></p>
|
||||
|
||||
|
||||
|
||||
<p>A cyclic rotation of the matrix is done by cyclically rotating <strong>each layer</strong> in the matrix. To cyclically rotate a layer once, each element in the layer will take the place of the adjacent element in the <strong>counter-clockwise</strong> direction. An example rotation is shown below:</p>
|
||||
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2021/06/22/explanation_grid.jpg" style="width: 500px; height: 268px;" />
|
||||
|
||||
<p>Return <em>the matrix after applying </em><code>k</code> <em>cyclic rotations to it</em>.</p>
|
||||
|
||||
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2021/06/19/rod2.png" style="width: 421px; height: 191px;" />
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> grid = [[40,10],[30,20]], k = 1
|
||||
|
||||
<strong>Output:</strong> [[10,20],[40,30]]
|
||||
|
||||
<strong>Explanation:</strong> The figures above represent the grid at every state.
|
||||
|
||||
</pre>
|
||||
|
||||
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
Reference in New Issue
Block a user