Skip to content

Commit 0c3fafc

Browse files
authored
feat: add typescript solution to lc problem: No.0518.Coin Change 2 (doocs#448)
1 parent 5bce6b9 commit 0c3fafc

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

solution/0500-0599/0518.Coin Change 2/README.md

+15
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,21 @@ class Solution {
9393
}
9494
```
9595

96+
### **TypeScript**
97+
98+
```ts
99+
function change(amount: number, coins: number[]): number {
100+
let dp = new Array(amount + 1).fill(0);
101+
dp[0] = 1;
102+
for (let coin of coins) {
103+
for (let i = coin; i <= amount; ++i) {
104+
dp[i] += dp[i - coin];
105+
}
106+
}
107+
return dp.pop();
108+
};
109+
```
110+
96111
### **Go**
97112

98113
```go

solution/0500-0599/0518.Coin Change 2/README_EN.md

+15
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,21 @@ class Solution {
129129
}
130130
```
131131

132+
### **TypeScript**
133+
134+
```ts
135+
function change(amount: number, coins: number[]): number {
136+
let dp = new Array(amount + 1).fill(0);
137+
dp[0] = 1;
138+
for (let coin of coins) {
139+
for (let i = coin; i <= amount; ++i) {
140+
dp[i] += dp[i - coin];
141+
}
142+
}
143+
return dp.pop();
144+
};
145+
```
146+
132147
### **Go**
133148

134149
```go
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function change(amount: number, coins: number[]): number {
2+
let dp = new Array(amount + 1).fill(0);
3+
dp[0] = 1;
4+
for (let coin of coins) {
5+
for (let i = coin; i <= amount; ++i) {
6+
dp[i] += dp[i - coin];
7+
}
8+
}
9+
return dp.pop();
10+
};

0 commit comments

Comments
 (0)