mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
Update 0518.零钱兑换II.md
Added python version code
This commit is contained in:
@ -101,7 +101,7 @@ dp[j] (考虑coins[i]的组合总和) 就是所有的dp[j - coins[i]](不
|
||||
|
||||
而本题要求凑成总和的组合数,元素之间要求没有顺序。
|
||||
|
||||
所以纯完全背包是能凑成总结就行,不用管怎么凑的。
|
||||
所以纯完全背包是能凑成总和就行,不用管怎么凑的。
|
||||
|
||||
本题是求凑出来的方案个数,且每个方案个数是为组合数。
|
||||
|
||||
@ -206,7 +206,16 @@ class Solution {
|
||||
```
|
||||
|
||||
Python:
|
||||
|
||||
```python
|
||||
class Solution:
|
||||
def change(self, amount: int, coins: List[int]) -> int:
|
||||
dp = [0] * (amount + 1)
|
||||
dp[0] = 1
|
||||
for i in range(len(coins)):
|
||||
for j in range(coins[i], amount + 1):
|
||||
dp[j] += dp[j - coins[i]]
|
||||
return dp[amount]
|
||||
```
|
||||
|
||||
Go:
|
||||
|
||||
|
Reference in New Issue
Block a user