Monday, May 2, 2016

Minimum coin numbers

this is somehow easy dynamic problem.

this is my python code
coins = [1, 2, 5, 10, 20, 50, 100, 500, 1000]

def find(coins, target):

    list = [];
    for i in reversed(range(len(coins))):
         print(coins[i])
         while target>= coins[i]:
             target = target - coins[i]
             list.append(coins[i])

    return list

list = find(coins, 93 )
print(list)

No comments:

Post a Comment