做个找硬币的问题,然后自己啃了一下相关的动态规划的资料,随笔如下
题目要求如下1
2
3
4
5
6
7
8
9
10
11
12
13
14Coin 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.
Example 1:
Input: coins = [1, 2, 5], amount = 11
Output: 3
Explanation: 11 = 5 + 5 + 1
Example 2:
Input: coins = [2], amount = 3
Output: -1
我写的代码:
1 | /** |
console.log(coinChange([1,2,5],11))
1 | /*我们如果硬币不能重复呢?,我们如何做*/ |
我没有写没有可以重复取硬币的记录,不过大同小异