LC 518 Coin Change 2(M)
You are given coins of different denominations and a total amount of money. Write a function to compute the number of combinations that make up that amount. You may assume that you have infinite number of each kind of coin.
Note: You can assume that
0 <= amount <= 5000 1 <= coin <= 5000 the number of coins is less than 500 the answer is guaranteed to fit into signed 32-bit integer
边界条件 如果 amount = 0, 直接返回1
解题思路 DP
用coin值为间隔距离, dp[a] = dp[a] + dp[a-coin] 累计每个amount点的组合值, 和 322 coin change 有类似的思路。
Last updated
Was this helpful?