mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-10 04:06:51 +08:00
Merge pull request #1286 from xiaofei-2020/dp19
添加(0518.零钱兑换II.md):增加typescript版本
This commit is contained in:
@ -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];
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-----------------------
|
-----------------------
|
||||||
|
Reference in New Issue
Block a user