File tree 3 files changed +39
-0
lines changed
solution/2400-2499/2406.Divide Intervals Into Minimum Number of Groups
3 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -130,6 +130,20 @@ func (h *hp) Pop() any {
130
130
}
131
131
```
132
132
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
+
133
147
<!-- tabs: end -->
134
148
135
149
<!-- end -->
Original file line number Diff line number Diff line change @@ -127,6 +127,20 @@ func (h *hp) Pop() any {
127
127
}
128
128
```
129
129
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
+
130
144
<!-- tabs: end -->
131
145
132
146
<!-- end -->
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments