[Python手撕]零錢兌換(組合總數,需要去重)

Duancf發表於2024-10-04
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]

相關文章