1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/最少操作使数组递增 [minimum-operations-to-make-the-array-increasing].html
2022-03-29 12:43:11 +08:00

43 lines
1.4 KiB
HTML
Raw 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>nums</code> <strong>下标从 0 开始</strong>)。每一次操作中,你可以选择数组中一个元素,并将它增加 <code>1</code> 。</p>
<ul>
<li>比方说,如果 <code>nums = [1,2,3]</code> ,你可以选择增加 <code>nums[1]</code> 得到 <code>nums = [1,<b>3</b>,3]</code> 。</li>
</ul>
<p>请你返回使 <code>nums</code> <strong>严格递增</strong> 的 <strong>最少</strong> 操作次数。</p>
<p>我们称数组 <code>nums</code> 是 <strong>严格递增的</strong> ,当它满足对于所有的 <code>0 &lt;= i &lt; nums.length - 1</code> 都有 <code>nums[i] &lt; nums[i+1]</code> 。一个长度为 <code>1</code> 的数组是严格递增的一种特殊情况。</p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre><b>输入:</b>nums = [1,1,1]
<b>输出:</b>3
<b>解释:</b>你可以进行如下操作:
1) 增加 nums[2] ,数组变为 [1,1,<strong>2</strong>] 。
2) 增加 nums[1] ,数组变为 [1,<strong>2</strong>,2] 。
3) 增加 nums[2] ,数组变为 [1,2,<strong>3</strong>] 。
</pre>
<p><strong>示例 2</strong></p>
<pre><b>输入:</b>nums = [1,5,2,4,1]
<b>输出:</b>14
</pre>
<p><strong>示例 3</strong></p>
<pre><b>输入:</b>nums = [8]
<b>输出:</b>0
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 5000</code></li>
<li><code>1 &lt;= nums[i] &lt;= 10<sup>4</sup></code></li>
</ul>