mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
添加(0518.零钱兑换II.md):增加typescript版本
This commit is contained in:
@ -258,6 +258,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];
|
||||
};
|
||||
```
|
||||
|
||||
|
||||
|
||||
-----------------------
|
||||
|
Reference in New Issue
Block a user