Merge pull request #1286 from xiaofei-2020/dp19

添加(0518.零钱兑换II.md):增加typescript版本
This commit is contained in:
程序员Carl
2022-05-23 10:27:34 +08:00
committed by GitHub

View File

@ -274,6 +274,21 @@ const change = (amount, coins) => {
} }
``` ```
TypeScript
```typescript
function change(amount: number, coins: number[]): number {
const dp: number[] = new Array(amount + 1).fill(0);
dp[0] = 1;
for (let i = 0, length = coins.length; i < length; i++) {
for (let j = coins[i]; j <= amount; j++) {
dp[j] += dp[j - coins[i]];
}
}
return dp[amount];
};
```
----------------------- -----------------------