1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-08 08:51:42 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee

移除零宽空格

This commit is contained in:
2025-05-25 15:06:02 +08:00
parent 59597532bc
commit 3070bed723
272 changed files with 1031 additions and 749 deletions

View File

@@ -7,9 +7,9 @@
"boundTopicId": 843782,
"title": "Cyclically Rotating a Grid",
"titleSlug": "cyclically-rotating-a-grid",
"content": "<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>\r\n\r\n<p>The matrix is composed of several layers, which is shown in the below image, where each color is its own layer:</p>\r\n\r\n<p><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/10/ringofgrid.png\" style=\"width: 231px; height: 258px;\" /></p>\r\n\r\n<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>\r\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/22/explanation_grid.jpg\" style=\"width: 500px; height: 268px;\" />\r\n<p>Return <em>the matrix after applying </em><code>k</code> <em>cyclic rotations to it</em>.</p>\r\n\r\n<p>&nbsp;</p>\r\n<p><strong class=\"example\">Example 1:</strong></p>\r\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/19/rod2.png\" style=\"width: 421px; height: 191px;\" />\r\n<pre>\r\n<strong>Input:</strong> grid = [[40,10],[30,20]], k = 1\r\n<strong>Output:</strong> [[10,20],[40,30]]\r\n<strong>Explanation:</strong> The figures above represent the grid at every state.\r\n</pre>\r\n\r\n<p><strong class=\"example\">Example 2:</strong></p>\r\n<strong><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/10/ringofgrid5.png\" style=\"width: 231px; height: 262px;\" /></strong> <strong><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/10/ringofgrid6.png\" style=\"width: 231px; height: 262px;\" /></strong> <strong><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/10/ringofgrid7.png\" style=\"width: 231px; height: 262px;\" /></strong>\r\n\r\n<pre>\r\n<strong>Input:</strong> grid = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]], k = 2\r\n<strong>Output:</strong> [[3,4,8,12],[2,11,10,16],[1,7,6,15],[5,9,13,14]]\r\n<strong>Explanation:</strong> The figures above represent the grid at every state.\r\n</pre>\r\n\r\n<p>&nbsp;</p>\r\n<p><strong>Constraints:</strong></p>\r\n\r\n<ul>\r\n\t<li><code>m == grid.length</code></li>\r\n\t<li><code>n == grid[i].length</code></li>\r\n\t<li><code>2 &lt;= m, n &lt;= 50</code></li>\r\n\t<li>Both <code>m</code> and <code>n</code> are <strong>even</strong> integers.</li>\r\n\t<li><code>1 &lt;= grid[i][j] &lt;=<sup> </sup>5000</code></li>\r\n\t<li><code>1 &lt;= k &lt;= 10<sup>9</sup></code></li>\r\n</ul>",
"content": "<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>\r\n\r\n<p>The matrix is composed of several layers, which is shown in the below image, where each color is its own layer:</p>\r\n\r\n<p><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/10/ringofgrid.png\" style=\"width: 231px; height: 258px;\" /></p>\r\n\r\n<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>\r\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/22/explanation_grid.jpg\" style=\"width: 500px; height: 268px;\" />\r\n<p>Return <em>the matrix after applying </em><code>k</code> <em>cyclic rotations to it</em>.</p>\r\n\r\n<p>&nbsp;</p>\r\n<p><strong class=\"example\">Example 1:</strong></p>\r\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/19/rod2.png\" style=\"width: 421px; height: 191px;\" />\r\n<pre>\r\n<strong>Input:</strong> grid = [[40,10],[30,20]], k = 1\r\n<strong>Output:</strong> [[10,20],[40,30]]\r\n<strong>Explanation:</strong> The figures above represent the grid at every state.\r\n</pre>\r\n\r\n<p><strong class=\"example\">Example 2:</strong></p>\r\n<strong><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/10/ringofgrid5.png\" style=\"width: 231px; height: 262px;\" /></strong> <strong><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/10/ringofgrid6.png\" style=\"width: 231px; height: 262px;\" /></strong> <strong><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/10/ringofgrid7.png\" style=\"width: 231px; height: 262px;\" /></strong>\r\n\r\n<pre>\r\n<strong>Input:</strong> grid = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]], k = 2\r\n<strong>Output:</strong> [[3,4,8,12],[2,11,10,16],[1,7,6,15],[5,9,13,14]]\r\n<strong>Explanation:</strong> The figures above represent the grid at every state.\r\n</pre>\r\n\r\n<p>&nbsp;</p>\r\n<p><strong>Constraints:</strong></p>\r\n\r\n<ul>\r\n\t<li><code>m == grid.length</code></li>\r\n\t<li><code>n == grid[i].length</code></li>\r\n\t<li><code>2 &lt;= m, n &lt;= 50</code></li>\r\n\t<li>Both <code>m</code> and <code>n</code> are <strong>even</strong> integers.</li>\r\n\t<li><code>1 &lt;= grid[i][j] &lt;=<sup> </sup>5000</code></li>\r\n\t<li><code>1 &lt;= k &lt;= 10<sup>9</sup></code></li>\r\n</ul>",
"translatedTitle": "循环轮转矩阵",
"translatedContent": "<p>给你一个大小为 <code>m x n</code> 的整数矩阵 <code>grid</code> ,其中 <code>m</code> 和 <code>n</code> 都是 <strong>偶数</strong> ;另给你一个整数 <code>k</code> 。</p>\n\n<p>矩阵由若干层组成,如下图所示,每种颜色代表一层:</p>\n\n<p><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/10/ringofgrid.png\" style=\"width: 231px; height: 258px;\"></p>\n\n<p>矩阵的循环轮转是通过分别循环轮转矩阵中的每一层完成的。在对某一层进行一次循环旋转操作时,层中的每一个元素将会取代其 <strong>逆时针 </strong>方向的相邻元素。轮转示例如下:</p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/22/explanation_grid.jpg\" style=\"width: 500px; height: 268px;\">\n<p>返回执行 <code>k</code> 次循环轮转操作后的矩阵。</p>\n\n<p> </p>\n\n<p><strong>示例 1</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/19/rod2.png\" style=\"width: 421px; height: 191px;\">\n<pre><strong>输入:</strong>grid = [[40,10],[30,20]], k = 1\n<strong>输出:</strong>[[10,20],[40,30]]\n<strong>解释:</strong>上图展示了矩阵在执行循环轮转操作时每一步的状态。</pre>\n\n<p><strong>示例 2</strong></p>\n<strong><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/10/ringofgrid5.png\" style=\"width: 231px; height: 262px;\"></strong> <strong><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/10/ringofgrid6.png\" style=\"width: 231px; height: 262px;\"></strong> <strong><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/10/ringofgrid7.png\" style=\"width: 231px; height: 262px;\"></strong>\n\n<pre><strong>输入:</strong>grid = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]], k = 2\n<strong>输出:</strong>[[3,4,8,12],[2,11,10,16],[1,7,6,15],[5,9,13,14]]\n<strong>解释:</strong>上图展示了矩阵在执行循环轮转操作时每一步的状态。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>m == grid.length</code></li>\n\t<li><code>n == grid[i].length</code></li>\n\t<li><code>2 &lt;= m, n &lt;= 50</code></li>\n\t<li><code>m</code> 和 <code>n</code> 都是 <strong>偶数</strong></li>\n\t<li><code>1 &lt;= grid[i][j] &lt;=<sup> </sup>5000</code></li>\n\t<li><code>1 &lt;= k &lt;= 10<sup>9</sup></code></li>\n</ul>\n",
"translatedContent": "<p>给你一个大小为 <code>m x n</code> 的整数矩阵 <code>grid</code> ,其中 <code>m</code> 和 <code>n</code> 都是 <strong>偶数</strong> ;另给你一个整数 <code>k</code> 。</p>\n\n<p>矩阵由若干层组成,如下图所示,每种颜色代表一层:</p>\n\n<p><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/10/ringofgrid.png\" style=\"width: 231px; height: 258px;\"></p>\n\n<p>矩阵的循环轮转是通过分别循环轮转矩阵中的每一层完成的。在对某一层进行一次循环旋转操作时,层中的每一个元素将会取代其 <strong>逆时针 </strong>方向的相邻元素。轮转示例如下:</p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/22/explanation_grid.jpg\" style=\"width: 500px; height: 268px;\">\n<p>返回执行 <code>k</code> 次循环轮转操作后的矩阵。</p>\n\n<p> </p>\n\n<p><strong>示例 1</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/19/rod2.png\" style=\"width: 421px; height: 191px;\">\n<pre><strong>输入:</strong>grid = [[40,10],[30,20]], k = 1\n<strong>输出:</strong>[[10,20],[40,30]]\n<strong>解释:</strong>上图展示了矩阵在执行循环轮转操作时每一步的状态。</pre>\n\n<p><strong>示例 2</strong></p>\n<strong><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/10/ringofgrid5.png\" style=\"width: 231px; height: 262px;\"></strong> <strong><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/10/ringofgrid6.png\" style=\"width: 231px; height: 262px;\"></strong> <strong><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/10/ringofgrid7.png\" style=\"width: 231px; height: 262px;\"></strong>\n\n<pre><strong>输入:</strong>grid = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]], k = 2\n<strong>输出:</strong>[[3,4,8,12],[2,11,10,16],[1,7,6,15],[5,9,13,14]]\n<strong>解释:</strong>上图展示了矩阵在执行循环轮转操作时每一步的状态。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>m == grid.length</code></li>\n\t<li><code>n == grid[i].length</code></li>\n\t<li><code>2 &lt;= m, n &lt;= 50</code></li>\n\t<li><code>m</code> 和 <code>n</code> 都是 <strong>偶数</strong></li>\n\t<li><code>1 &lt;= grid[i][j] &lt;=<sup> </sup>5000</code></li>\n\t<li><code>1 &lt;= k &lt;= 10<sup>9</sup></code></li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 28,