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)/执行操作使数据元素之和大于等于 K [apply-operations-to-make-sum-of-array-greater-than-or-equal-to-k].html
2024-03-28 09:27:27 +08:00

53 lines
1.8 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>给你一个<strong>正整数</strong> <code>k</code> 。最初,你有一个数组 <code>nums = [1]</code></p>
<p>你可以对数组执行以下 <strong>任意 </strong>操作 <strong>任意 </strong>次数(<strong>可能为零</strong></p>
<ul>
<li>选择数组中的任何一个元素,然后将它的值<strong> 增加</strong> <code>1</code></li>
<li>复制数组中的任何一个元素,然后将它附加到数组的末尾。</li>
</ul>
<p>返回使得最终数组元素之<strong></strong>大于或等于 <code>k</code> 所需的 <strong>最少 </strong>操作次数。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">k = 11</span></p>
<p><strong>输出:</strong><span class="example-io">5</span></p>
<p><strong>解释:</strong></p>
<p>可以对数组 <code>nums = [1]</code> 执行以下操作:</p>
<ul>
<li>将元素的值增加 <code>1</code> 三次。结果数组为 <code>nums = [4]</code></li>
<li>复制元素两次。结果数组为 <code>nums = [4,4,4]</code></li>
</ul>
<p>最终数组的和为 <code>4 + 4 + 4 = 12</code> ,大于等于 <code>k = 11</code><br />
执行的总操作次数为 <code>3 + 2 = 5</code></p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">k = 1</span></p>
<p><strong>输出:</strong><span class="example-io">0</span></p>
<p><strong>解释:</strong></p>
<p>原始数组的和已经大于等于 <code>1</code> ,因此不需要执行操作。</p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= k &lt;= 10<sup>5</sup></code></li>
</ul>