518. 零钱兑换 II_动态规划

518. 零钱兑换 II_动态规划_第1张图片

class Solution(object):
    def change(self, amount, coins):
        """
        :type amount: int
        :type coins: List[int]
        :rtype: int
        """
        res=[0]*(amount+1)
        res[0]=1

        for c in coins:
            for j in range(1,amount+1):
                if j>=c:
                    res[j]=res[j]+res[j-c]

        return res[amount]

# print Solution().change(amount = 5, coins = [1, 2, 5])

 

你可能感兴趣的:(编程题,编程题)