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)/使每一列严格递增的最少操作次数 [minimum-operations-to-make-columns-strictly-increasing].html
2025-01-09 01:30:35 +08:00

50 lines
2.2 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>给你一个由&nbsp;<b>非负&nbsp;</b>整数组成的 <code>m x n</code> 矩阵 <code>grid</code></p>
<p>在一次操作中,你可以将任意元素 <code>grid[i][j]</code> 的值增加 1。</p>
<p>返回使 <code>grid</code> 的所有列&nbsp;<strong>严格递增&nbsp;</strong>所需的&nbsp;<strong>最少&nbsp;</strong>操作次数。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">grid = [[3,2],[1,3],[3,4],[0,1]]</span></p>
<p><strong>输出:</strong> <span class="example-io">15</span></p>
<p><strong>解释:</strong></p>
<ul>
<li>为了让第 <code>0</code>&nbsp;列严格递增,可以对 <code>grid[1][0]</code> 执行 3 次操作,对 <code>grid[2][0]</code> 执行 2 次操作,对 <code>grid[3][0]</code> 执行 6 次操作。</li>
<li>为了让第 <code>1</code>&nbsp;列严格递增,可以对 <code>grid[3][1]</code> 执行 4 次操作。</li>
</ul>
<img alt="" src="https://assets.leetcode.com/uploads/2024/11/10/firstexample.png" style="width: 200px; height: 347px;" /></div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">grid = [[3,2,1],[2,1,0],[1,2,3]]</span></p>
<p><strong>输出:</strong> <span class="example-io">12</span></p>
<p><strong>解释:</strong></p>
<ul>
<li>为了让第 <code>0</code>&nbsp;列严格递增,可以对 <code>grid[1][0]</code> 执行 2 次操作,对 <code>grid[2][0]</code> 执行 4 次操作。</li>
<li>为了让第 <code>1</code>&nbsp;列严格递增,可以对 <code>grid[1][1]</code> 执行 2 次操作,对 <code>grid[2][1]</code> 执行 2 次操作。</li>
<li>为了让第 <code>2</code>&nbsp;列严格递增,可以对 <code>grid[1][2]</code> 执行 2 次操作。</li>
</ul>
<img alt="" src="https://assets.leetcode.com/uploads/2024/11/10/secondexample.png" style="width: 300px; height: 257px;" /></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>0 &lt;= grid[i][j] &lt; 2500</code></li>
</ul>