class Solution:
def coinChange(self, coins: list[int], amount: int) -> int:
dp = [0] + [0xFFFFFFFF] * (amount)
for coin in coins:
for i in range(coin, amount + 1):
dp[i] = min(dp[i], dp[i - coin] + 1)
return (dp[-1], -1)[dp[-1] == 0xFFFFFFFF]
322. Coin Change - LeetCode
· One min read