Coin Change【硬币找零】

来源:互联网 发布:淘宝关键词搜索设置 编辑:程序博客网 时间:2024/06/08 01:28

一、题目

英文: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代码

五、递归循环图解



原创粉丝点击