问题描述 yo are given coins of different denominations and a total amo nt of money amo nt. write a f nction to comp te the fewest n mber of coins that yo need to make p that amo nt. if that amo nt of money cannot be made p by any combination of the coins, ret rn -1. example 1: inp t: coins = [1, 2, 5], amo nt = 11 o tp t: 3 (11 = 5 + 5 + 1) example 2: inp t: coins = [2], amo nt = 3 o tp t: -1 note: yo may ass me that yo have an infinite n mber of each kind of coin. 思路 运用动态规划,用一个list记录0至amo nt之间,凑到各个价格所需要的coin数量,初始除了价格为0时需要0个coin,其余价格需要inf个 从小到大循环一遍,对于每个coin: 凑到某个价格x所需要的coin数量 = 当前所需数量与凑到(x-coin)的价格所需要的coin数量+1间的最小值 def coinchange(self, coins, amo nt):  :type coins: list[int] :type amo nt: int :rtype: int  dp = [0] + [float( inf )] * amo nt coins.sort for c in coins: for i in range(c, amo nt+1): dp[i] = min(dp[i], dp[i-c]+1) ret rn dp[-1] if dp[-1] !