Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 216088f

Browse files
Update 背包问题理论基础完全背包.md
添加 python3 版本代码
1 parent 8d93b1e commit 216088f

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

‎problems/0518.零钱兑换II.md‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
示例 3:
3434
输入: amount = 10, coins = [10]
3535
输出: 1
36-
36+
3737
注意,你可以假设:
3838

3939
* 0 <= amount (总金额) <= 5000
@@ -207,6 +207,21 @@ class Solution {
207207

208208
Python:
209209

210+
```python3
211+
class Solution:
212+
def change(self, amount: int, coins: List[int]) -> int:
213+
dp = [0]*(amount + 1)
214+
dp[0] = 1
215+
# 遍历物品
216+
for i in range(len(coins)):
217+
# 遍历背包
218+
for j in range(coins[i], amount + 1):
219+
dp[j] += dp[j - coins[i]]
220+
return dp[amount]
221+
```
222+
223+
224+
210225

211226
Go:
212227

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /