We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f1f7933 commit 7ca169fCopy full SHA for 7ca169f
coin-change/jun0811.js
@@ -0,0 +1,13 @@
1
+var coinChange = function(coins, amount) {
2
+ if(amount == 0) return 0
3
+
4
+ const dp = [0, ...new Array(amount).fill(amount+1)]
5
6
+ for (const coin of coins) {
7
+ for (let i = coin; i <=amount; i++) {
8
+ dp[i] = Math.min(dp[i], dp[i-coin] + 1)
9
+ }
10
11
12
+ return dp[amount] < amount+1 ? dp[amount] : -1
13
+};
0 commit comments