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.
2 parents 948aeb6 + b2f06e6 commit dee23f1Copy full SHA for dee23f1
javascript/322-Coin-Change.js
@@ -0,0 +1,17 @@
1
+/**
2
+ * @param {number[]} coins
3
+ * @param {number} amount
4
+ * @return {number}
5
+ */
6
+var coinChange = function(coins, amount) {
7
+ let dp = Array(amount+1).fill(amount+1)
8
+ dp[0]=0
9
+ for(let i=1; i<dp.length; i++) {
10
+ for(const coin of coins) {
11
+ if(i-coin >= 0) {
12
+ dp[i] = Math.min(dp[i], 1 + dp[i-coin])
13
+ }
14
15
16
+ return dp[amount] === amount+1 ? -1 : dp.pop()
17
+};
0 commit comments