add js solution for coin-change-2

This commit is contained in:
Qi Jia 2021-07-05 16:57:23 -07:00 committed by GitHub
parent 1da6ff725a
commit 01ee8a2d57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 0 deletions

View File

@ -243,6 +243,22 @@ func change(amount int, coins []int) int {
}
```
Javascript
```javascript
const change = (amount, coins) => {
let dp = 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 dp[amount];
}
```
-----------------------