Skip to content

Commit 91a9a6a

Browse files
committed
feat: add solutions to lc problem: No.2585
No.2585.Number of Ways to Earn Points
1 parent 5cc3709 commit 91a9a6a

File tree

4 files changed

+64
-1
lines changed

4 files changed

+64
-1
lines changed

README_EN.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414

1515
## Introduction
1616

17-
Complete solutions to LeetCode, LCOF and LCCI problems, updated daily. Please give me a [star](https://github.com/doocs/leetcode) 🌟 if you like it.
17+
The Doocs LeetCode repository is a comprehensive collection of solutions to LeetCode questions in multiple programming languages. The repository contains solutions to LeetCode, LCOF, LCCI questions, and more in multiple programming languages.
18+
19+
The repository is maintained by the Doocs community, and please give us a [star](https://github.com/doocs/leetcode) 🌟 if you like it.
1820

1921
[中文文档](/README.md)
2022

solution/2500-2599/2585.Number of Ways to Earn Points/README.md

+22
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,28 @@ func waysToReachTarget(target int, types [][]int) int {
181181
}
182182
```
183183

184+
### **TypeScript**
185+
186+
```ts
187+
function waysToReachTarget(target: number, types: number[][]): number {
188+
const n = types.length;
189+
const mod = 10 ** 9 + 7;
190+
const f: number[][] = Array.from({ length: n + 1 }, () => Array(target + 1).fill(0));
191+
f[0][0] = 1;
192+
for (let i = 1; i <= n; ++i) {
193+
const [count, marks] = types[i - 1];
194+
for (let j = 0; j <= target; ++j) {
195+
for (let k = 0; k <= count; ++k) {
196+
if (j >= k * marks) {
197+
f[i][j] = (f[i][j] + f[i - 1][j - k * marks]) % mod;
198+
}
199+
}
200+
}
201+
}
202+
return f[n][target];
203+
};
204+
```
205+
184206
### **...**
185207

186208
```

solution/2500-2599/2585.Number of Ways to Earn Points/README_EN.md

+22
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,28 @@ func waysToReachTarget(target int, types [][]int) int {
161161
}
162162
```
163163

164+
### **TypeScript**
165+
166+
```ts
167+
function waysToReachTarget(target: number, types: number[][]): number {
168+
const n = types.length;
169+
const mod = 10 ** 9 + 7;
170+
const f: number[][] = Array.from({ length: n + 1 }, () => Array(target + 1).fill(0));
171+
f[0][0] = 1;
172+
for (let i = 1; i <= n; ++i) {
173+
const [count, marks] = types[i - 1];
174+
for (let j = 0; j <= target; ++j) {
175+
for (let k = 0; k <= count; ++k) {
176+
if (j >= k * marks) {
177+
f[i][j] = (f[i][j] + f[i - 1][j - k * marks]) % mod;
178+
}
179+
}
180+
}
181+
}
182+
return f[n][target];
183+
};
184+
```
185+
164186
### **...**
165187

166188
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function waysToReachTarget(target: number, types: number[][]): number {
2+
const n = types.length;
3+
const mod = 10 ** 9 + 7;
4+
const f: number[][] = Array.from({ length: n + 1 }, () => Array(target + 1).fill(0));
5+
f[0][0] = 1;
6+
for (let i = 1; i <= n; ++i) {
7+
const [count, marks] = types[i - 1];
8+
for (let j = 0; j <= target; ++j) {
9+
for (let k = 0; k <= count; ++k) {
10+
if (j >= k * marks) {
11+
f[i][j] = (f[i][j] + f[i - 1][j - k * marks]) % mod;
12+
}
13+
}
14+
}
15+
}
16+
return f[n][target];
17+
};

0 commit comments

Comments
 (0)