File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed
Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ # Time Complexity: O(nlogn)
3+ # Space Complexity: O(n)
4+ */
5+
6+ class Solution {
7+
8+ private class Info {
9+ int kind ; // start = 0, end = 1
10+ int time ;
11+
12+ Info (int kind , int time ) {
13+ this .kind = kind ;
14+ this .time = time ;
15+ }
16+ }
17+ public int minMeetingRooms (int [][] intervals ) {
18+ int n = intervals .length ;
19+ List <Info > infos = new ArrayList <>();
20+ for (int i = 0 ; i < n ; i ++) {
21+ infos .add (new Info (0 , intervals [i ][0 ]));
22+ infos .add (new Info (1 , intervals [i ][1 ]));
23+ }
24+
25+ Collections .sort (infos , (o1 , o2 ) -> {
26+ if (o1 .time == o2 .time ) {
27+ return Integer .compare (o2 .kind , o1 .kind );
28+ }
29+ return Integer .compare (o1 .time , o2 .time );
30+ });
31+
32+ int cnt = 0 ;
33+ int ans = 0 ;
34+ for (Info info : infos ) {
35+ if (info .kind == 0 ) cnt ++;
36+ else cnt --;
37+ ans = Math .max (ans , cnt );
38+ }
39+
40+ return ans ;
41+ }
42+ }
You can’t perform that action at this time.
0 commit comments