Loading

[Python手撕]零钱兑换(组合总数,需要去重)

class Solution:
    def change(self, amount: int, coins: List[int]) -> int:

        dp = [0]*(amount+1)
        dp[0] = 1
		# 从面值开始遍历是为了去重
        for c in coins:
            for i in range(c,amount+1):
                dp[i] += dp[i-c]
        return dp[-1]
posted @ 2024-10-04 11:41  Duancf  阅读(22)  评论(0)    收藏  举报