Skip to content

Commit ccf3b44

Browse files
authored
feat: add ts solution to lc problem: No.2406 (doocs#2738)
1 parent 2ea76d7 commit ccf3b44

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

solution/2400-2499/2406.Divide Intervals Into Minimum Number of Groups/README.md

+14
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,20 @@ func (h *hp) Pop() any {
130130
}
131131
```
132132

133+
```ts
134+
function minGroups(intervals: number[][]): number {
135+
intervals.sort((a, b) => a[0] - b[0]);
136+
const q = new PriorityQueue({ compare: (a, b) => a - b });
137+
for (const [l, r] of intervals) {
138+
if (!q.isEmpty() && q.front() < l) {
139+
q.dequeue();
140+
}
141+
q.enqueue(r);
142+
}
143+
return q.size();
144+
}
145+
```
146+
133147
<!-- tabs:end -->
134148

135149
<!-- end -->

solution/2400-2499/2406.Divide Intervals Into Minimum Number of Groups/README_EN.md

+14
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,20 @@ func (h *hp) Pop() any {
127127
}
128128
```
129129

130+
```ts
131+
function minGroups(intervals: number[][]): number {
132+
intervals.sort((a, b) => a[0] - b[0]);
133+
const q = new PriorityQueue({ compare: (a, b) => a - b });
134+
for (const [l, r] of intervals) {
135+
if (!q.isEmpty() && q.front() < l) {
136+
q.dequeue();
137+
}
138+
q.enqueue(r);
139+
}
140+
return q.size();
141+
}
142+
```
143+
130144
<!-- tabs:end -->
131145

132146
<!-- end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function minGroups(intervals: number[][]): number {
2+
intervals.sort((a, b) => a[0] - b[0]);
3+
const q = new PriorityQueue({ compare: (a, b) => a - b });
4+
for (const [l, r] of intervals) {
5+
if (!q.isEmpty() && q.front() < l) {
6+
q.dequeue();
7+
}
8+
q.enqueue(r);
9+
}
10+
return q.size();
11+
}

0 commit comments

Comments
 (0)