Leetcode 518 Solution

This article provides solution to leetcode question 518 (coin-change-2).

https://leetcode.com/problems/coin-change-2

Solution

class Solution:
    def change(self, amount: int, coins: List[int]) -> int:
        dp = [0] * (amount + 1)
        dp[0] = 1

        for coin in coins:
            for i in range(amount + 1):
                if i - coin >= 0:
                    dp[i] += dp[i - coin]

        return dp[-1]