mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
54 lines
1.5 KiB
HTML
54 lines
1.5 KiB
HTML
<p>给定不同面额的硬币 <code>coins</code> 和一个总金额 <code>amount</code>。编写一个函数来计算可以凑成总金额所需的最少的硬币个数。如果没有任何一种硬币组合能组成总金额,返回 <code>-1</code>。</p>
|
||
|
||
<p>你可以认为每种硬币的数量是无限的。</p>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>示例 1:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>coins = <code>[1, 2, 5]</code>, amount = <code>11</code>
|
||
<strong>输出:</strong><code>3</code>
|
||
<strong>解释:</strong>11 = 5 + 5 + 1</pre>
|
||
|
||
<p><strong>示例 2:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>coins = <code>[2]</code>, amount = <code>3</code>
|
||
<strong>输出:</strong>-1</pre>
|
||
|
||
<p><strong>示例 3:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>coins = [1], amount = 0
|
||
<strong>输出:</strong>0
|
||
</pre>
|
||
|
||
<p><strong>示例 4:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>coins = [1], amount = 1
|
||
<strong>输出:</strong>1
|
||
</pre>
|
||
|
||
<p><strong>示例 5:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>coins = [1], amount = 2
|
||
<strong>输出:</strong>2
|
||
</pre>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>提示:</strong></p>
|
||
|
||
<ul>
|
||
<li><code>1 <= coins.length <= 12</code></li>
|
||
<li><code>1 <= coins[i] <= 2<sup>31</sup> - 1</code></li>
|
||
<li><code>0 <= amount <= 10<sup>4</sup></code></li>
|
||
</ul>
|
||
|
||
<p> </p>
|
||
|
||
<p><meta charset="UTF-8" />注意:本题与主站 322 题相同: <a href="https://leetcode-cn.com/problems/coin-change/">https://leetcode-cn.com/problems/coin-change/</a></p>
|