From 216088fe7c0d5192f4128084de9548848283a818 Mon Sep 17 00:00:00 2001 From: haofeng <852172305@qq.com> Date: Mon, 7 Jun 2021 23:17:38 +0800 Subject: [PATCH] =?UTF-8?q?Update=20=E8=83=8C=E5=8C=85=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E7=90=86=E8=AE=BA=E5=9F=BA=E7=A1=80=E5=AE=8C=E5=85=A8=E8=83=8C?= =?UTF-8?q?=E5=8C=85.md=20=E6=B7=BB=E5=8A=A0=20python3=20=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0518.零钱兑换II.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/problems/0518.零钱兑换II.md b/problems/0518.零钱兑换II.md index 2dee030c..08aff9ac 100644 --- a/problems/0518.零钱兑换II.md +++ b/problems/0518.零钱兑换II.md @@ -33,7 +33,7 @@ 示例 3: 输入: amount = 10, coins = [10] 输出: 1 -  + 注意,你可以假设: * 0 <= amount (总金额) <= 5000 @@ -207,6 +207,21 @@ class Solution { Python: +```python3 +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: