问题描述:现在有2元、1元、0.5元、0.2元、0.1元、0.05元的纸币,如何才能使得找零的的张数最小
基本思路;将纸币从大到小排序,尽可能地先找大额的;
coins = [2,1,0.5,0.2,0.1,0.05] money = 5.65 def coinChange(coins,money): count = 0 i = 0 res=[] while i<len(coins): if money>=coins[i]: n=int(money/coins[i]) for _ in range(n): res.append(coins[i]) count+=n change=n*coins[i] money=money-change i+=1 return count,res