Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e4dbb95

Browse files
committed
feat: 零钱兑换
1 parent 378a297 commit e4dbb95

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

动态规划/零钱兑换II-518.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @param {number} amount
3+
* @param {number[]} coins
4+
* @return {number}
5+
*/
6+
let change = function (amount, coins) {
7+
let dp = new Array(amount + 1).fill(0);
8+
9+
dp[0] = 1;
10+
11+
for (let coin of coins) {
12+
for (let i = 1; i <= amount; i++) {
13+
if (i >= coin) {
14+
dp[i] += dp[i - coin];
15+
}
16+
}
17+
}
18+
19+
return dp[amount];
20+
};
21+
22+
console.log(change(5, [1, 2, 5]));

0 commit comments

Comments
 (0)