def greedy_change(amount, coins): coins.sort(reverse=True) # 将硬币按面额从大到小排序 change = [] for coin in coins: while amount >= coin: amount -= coin change.append(coin) # 将硬币加入到找零列表中 return change s = greedy_change(10,[1,2,3]) print(s)
标签:coins,amount,greedy,零钱,算法,coin,change,贪心 From: https://www.cnblogs.com/chaojiyingxiong/p/17802317.html