Leetcode 322 Solution

This article provides solution to leetcode question 322 (coin-change)

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

Solution

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

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

        return dp[amount] if dp[amount] != sys.maxsize else -1