一、题目
英文:Coin Change
中文:硬币找零
二、内容要求
英文:You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return
-1
.
中文:这道题给我们了一些可用的硬币值,又给了一个钱数,问我们最小能用几个硬币来找零。
三、示例
示例 1:
coins = [1, 2, 5]
, amount = 11
return 3
(11 = 5 + 5 + 1)
示例 2:
coins = [2]
, amount = 3
return -1
.
四、代码
java代码