Skip to content

Commit 7d4e120

Browse files
committedApr 23, 2025
Add solution #1621
1 parent b2fd42c commit 7d4e120

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed
 

‎README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,426 LeetCode solutions in JavaScript
1+
# 1,427 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1250,6 +1250,7 @@
12501250
1617|[Count Subtrees With Max Distance Between Cities](./solutions/1617-count-subtrees-with-max-distance-between-cities.js)|Hard|
12511251
1619|[Mean of Array After Removing Some Elements](./solutions/1619-mean-of-array-after-removing-some-elements.js)|Easy|
12521252
1620|[Coordinate With Maximum Network Quality](./solutions/1620-coordinate-with-maximum-network-quality.js)|Medium|
1253+
1621|[Number of Sets of K Non-Overlapping Line Segments](./solutions/1621-number-of-sets-of-k-non-overlapping-line-segments.js)|Medium|
12531254
1657|[Determine if Two Strings Are Close](./solutions/1657-determine-if-two-strings-are-close.js)|Medium|
12541255
1668|[Maximum Repeating Substring](./solutions/1668-maximum-repeating-substring.js)|Easy|
12551256
1669|[Merge In Between Linked Lists](./solutions/1669-merge-in-between-linked-lists.js)|Medium|
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* 1621. Number of Sets of K Non-Overlapping Line Segments
3+
* https://leetcode.com/problems/number-of-sets-of-k-non-overlapping-line-segments/
4+
* Difficulty: Medium
5+
*
6+
* Given n points on a 1-D plane, where the ith point (from 0 to n-1) is at x = i, find the number
7+
* of ways we can draw exactly k non-overlapping line segments such that each segment covers two
8+
* or more points. The endpoints of each segment must have integral coordinates. The k line segments
9+
* do not have to cover all n points, and they are allowed to share endpoints.
10+
*
11+
* Return the number of ways we can draw k non-overlapping line segments. Since this number can be
12+
* huge, return it modulo 109 + 7.
13+
*/
14+
15+
/**
16+
* @param {number} n
17+
* @param {number} k
18+
* @return {number}
19+
*/
20+
var numberOfSets = function(n, k) {
21+
const MOD = 1e9 + 7;
22+
const comb = Array.from({ length: n + k }, () => Array(n + k).fill(0));
23+
24+
for (let i = 0; i < n + k; i++) {
25+
comb[i][0] = 1;
26+
for (let j = 1; j <= i; j++) {
27+
comb[i][j] = (comb[i - 1][j - 1] + comb[i - 1][j]) % MOD;
28+
}
29+
}
30+
31+
return comb[n + k - 1][2 * k];
32+
};

0 commit comments

Comments
 (0)
Please sign in to comment.