0%
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| class Solution: def coinChange(self, coins: List[int], amount: int) -> int: d = [2**31-1 for _ in range(amount+1)] d[0]=0 for i in range(len(coins)): for j in range(coins[i],amount+1): d[j] = min(d[j],d[j-coins[i]]+1) if d[amount]==2**31-1: return -1 return d[amount]
|