1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-04 15:01:40 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
Files
leetcode-problemset/leetcode-cn/problem (Chinese)/垂直翻转子矩阵 [flip-square-submatrix-vertically].html
2025-08-10 21:35:14 +08:00

48 lines
1.9 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

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 x n</code> 的整数矩阵 <code>grid</code>,以及三个整数 <code>x</code><code>y</code><code>k</code></p>
<p>整数 <code>x</code><code>y</code> 表示一个&nbsp;<strong>正方形子矩阵&nbsp;</strong>的左上角下标,整数 <code>k</code> 表示该正方形子矩阵的边长。</p>
<p>你的任务是垂直翻转子矩阵的行顺序。</p>
<p>返回更新后的矩阵。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2025/07/20/gridexmdrawio.png" style="width: 300px; height: 116px;" />
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">grid = </span>[[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]<span class="example-io">, x = 1, y = 0, k = 3</span></p>
<p><strong>输出:</strong> <span class="example-io">[[1,2,3,4],[13,14,15,8],[9,10,11,12],[5,6,7,16]]</span></p>
<p><strong>解释:</strong></p>
<p>上图展示了矩阵在变换前后的样子。</p>
</div>
<p><strong class="example">示例 2</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2025/07/20/gridexm2drawio.png" style="width: 350px; height: 68px;" />
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">grid = [[3,4,2,3],[2,3,4,2]], x = 0, y = 2, k = 2</span></p>
<p><strong>输出:</strong> <span class="example-io">[[3,4,4,2],[2,3,2,3]]</span></p>
<p><strong>解释:</strong></p>
<p>上图展示了矩阵在变换前后的样子。</p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>m == grid.length</code></li>
<li><code>n == grid[i].length</code></li>
<li><code>1 &lt;= m, n &lt;= 50</code></li>
<li><code>1 &lt;= grid[i][j] &lt;= 100</code></li>
<li><code>0 &lt;= x &lt; m</code></li>
<li><code>0 &lt;= y &lt; n</code></li>
<li><code>1 &lt;= k &lt;= min(m - x, n - y)</code></li>
</ul>