// 找零钱 完全背包function change(amount, coins) { let dp = new Array(amount + 1).fill(0); dp[0] = 1; for (let i = 0; i < coins.length; i++) { for (let j = coins[i]; j <= amount; j++) { dp[j] += dp[j - coins[i]] } } return de[amount];}
// 零钱兑换 最少数量
function change(amount, coins) {
let dp = new Array(amount + 1).fill(0);
dp[0] = 1;
for (let i = 0; i < amount; i++) {
for (let j = 0; j <= coins.length; j++) {
if(coins[j]<=i){
dp[i] = Math.min(dp[i],dp[i - coins[j]]+1)
}
}
}
return de[amount]>amount?-1:dp[amount];
}