1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/二维网格迁移 [shift-2d-grid].html
2022-03-29 12:43:11 +08:00

52 lines
1.8 KiB
HTML
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你一个 <code>m</code><code>n</code> 列的二维网格 <code>grid</code> 和一个整数 <code>k</code>。你需要将 <code>grid</code> 迁移 <code>k</code> 次。</p>
<p>每次「迁移」操作将会引发下述活动:</p>
<ul>
<li>位于 <code>grid[i][j]</code> 的元素将会移动到 <code>grid[i][j + 1]</code></li>
<li>位于 <code>grid[i][n - 1]</code> 的元素将会移动到 <code>grid[i + 1][0]</code></li>
<li>位于 <code>grid[m - 1][n - 1]</code> 的元素将会移动到 <code>grid[0][0]</code></li>
</ul>
<p>请你返回 <code>k</code> 次迁移操作后最终得到的 <strong>二维网格</strong></p>
<p> </p>
<p><strong>示例 1</strong></p>
<p><img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2019/11/16/e1-1.png" style="height: 158px; width: 400px;" /></p>
<pre>
<code><strong>输入:</strong>grid</code> = [[1,2,3],[4,5,6],[7,8,9]], k = 1
<strong>输出:</strong>[[9,1,2],[3,4,5],[6,7,8]]
</pre>
<p><strong>示例 2</strong></p>
<p><img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2019/11/16/e2-1.png" style="height: 166px; width: 400px;" /></p>
<pre>
<code><strong>输入:</strong>grid</code> = [[3,8,1,9],[19,7,2,5],[4,6,11,10],[12,0,21,13]], k = 4
<strong>输出:</strong>[[12,0,21,13],[3,8,1,9],[19,7,2,5],[4,6,11,10]]
</pre>
<p><strong>示例 3</strong></p>
<pre>
<code><strong>输入:</strong>grid</code> = [[1,2,3],[4,5,6],[7,8,9]], k = 9
<strong>输出:</strong>[[1,2,3],[4,5,6],[7,8,9]]
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>m == grid.length</code></li>
<li><code>n == grid[i].length</code></li>
<li><code>1 <= m <= 50</code></li>
<li><code>1 <= n <= 50</code></li>
<li><code>-1000 <= grid[i][j] <= 1000</code></li>
<li><code>0 <= k <= 100</code></li>
</ul>