mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-04 15:01:40 +08:00
46 lines
2.0 KiB
HTML
46 lines
2.0 KiB
HTML
<p>You are given an <code>m x n</code> integer matrix <code>grid</code>, and three integers <code>x</code>, <code>y</code>, and <code>k</code>.</p>
|
||
|
||
<p>The integers <code>x</code> and <code>y</code> represent the row and column indices of the <strong>top-left</strong> corner of a <strong>square</strong> submatrix and the integer <code>k</code> represents the size (side length) of the square submatrix.</p>
|
||
|
||
<p>Your task is to flip the submatrix by reversing the order of its rows vertically.</p>
|
||
|
||
<p>Return the updated matrix.</p>
|
||
|
||
<p> </p>
|
||
<p><strong class="example">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>Input:</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>Output:</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>Explanation:</strong></p>
|
||
|
||
<p>The diagram above shows the grid before and after the transformation.</p>
|
||
</div>
|
||
|
||
<p><strong class="example">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>Input:</strong> <span class="example-io">grid = [[3,4,2,3],[2,3,4,2]], x = 0, y = 2, k = 2</span></p>
|
||
|
||
<p><strong>Output:</strong> <span class="example-io">[[3,4,4,2],[2,3,2,3]]</span></p>
|
||
|
||
<p><strong>Explanation:</strong></p>
|
||
|
||
<p>The diagram above shows the grid before and after the transformation.</p>
|
||
</div>
|
||
|
||
<p> </p>
|
||
<p><strong>Constraints:</strong></p>
|
||
|
||
<ul>
|
||
<li><code>m == grid.length</code></li>
|
||
<li><code>n == grid[i].length</code></li>
|
||
<li><code>1 <= m, n <= 50</code></li>
|
||
<li><code>1 <= grid[i][j] <= 100</code></li>
|
||
<li><code>0 <= x < m</code></li>
|
||
<li><code>0 <= y < n</code></li>
|
||
<li><code>1 <= k <= min(m - x, n - y)</code></li>
|
||
</ul>
|