coin change problem dynamic programming python with float

Solutions on MaxInterview for coin change problem dynamic programming python with float by the best coders in the world

showing results for - "coin change problem dynamic programming python with float"
Maya
25 Jan 2017
1def coinChange(self, coins: List[int], amount: int) -> int:
2        if amount == 0:
3            return 0
4
5        cols = amount + 1
6        T = [0 if idx == 0 else float('inf') for idx in range(cols)]
7
8        for j in range(len(coins)):
9            for i in range(1, cols): 
10                coin = coins[j]
11                if(i >= coins[j]):
12                    T[i] = min(T[i], T[i - coin] + 1)
13
14        return -1 if (T[-1] == float('inf')) else T[-1]
15