<gh_stars>1-10
"""
188 / 188 test cases passed.
Runtime: 1116 ms
Memory Usage: 15.1 MB
"""
class Solution:
    def coinChange(self, coins: List[int], amount: int) -> int:
        dp = [amount + 1] * (amount + 1)
        dp[0] = 0
        for coin in coins:
            for x in range(coin, amount + 1):
                dp[x] = min(dp[x], dp[x - coin] + 1)
        return dp[amount] if dp[amount] <= amount else -1
