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)/你能构造出连续值的最大数目 [maximum-number-of-consecutive-values-you-can-make].html
2022-03-29 12:43:11 +08:00

50 lines
1.5 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>n</code> 的整数数组 <code>coins</code> ,它代表你拥有的 <code>n</code> 个硬币。第 <code>i</code> 个硬币的值为 <code>coins[i]</code> 。如果你从这些硬币中选出一部分硬币,它们的和为 <code>x</code> ,那么称,你可以 <strong>构造</strong> 出 <code>x</code> 。</p>
<p>请返回从 <code>0</code> 开始(<strong>包括</strong> <code>0</code> ),你最多能 <strong>构造</strong> 出多少个连续整数。</p>
<p>你可能有多个相同值的硬币。</p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre>
<b>输入:</b>coins = [1,3]
<b>输出:</b>2
<strong>解释:</strong>你可以得到以下这些值:
- 0什么都不取 []
- 1取 [1]
从 0 开始,你可以构造出 2 个连续整数。</pre>
<p><strong>示例 2</strong></p>
<pre>
<b>输入:</b>coins = [1,1,1,4]
<b>输出:</b>8
<strong>解释:</strong>你可以得到以下这些值:
- 0什么都不取 []
- 1取 [1]
- 2取 [1,1]
- 3取 [1,1,1]
- 4取 [4]
- 5取 [4,1]
- 6取 [4,1,1]
- 7取 [4,1,1,1]
从 0 开始,你可以构造出 8 个连续整数。</pre>
<p><strong>示例 3</strong></p>
<pre>
<b>输入:</b>nums = [1,4,10,3,1]
<b>输出:</b>20</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>coins.length == n</code></li>
<li><code>1 <= n <= 4 * 10<sup>4</sup></code></li>
<li><code>1 <= coins[i] <= 4 * 10<sup>4</sup></code></li>
</ul>