Skip to content

Commit fc215a1

Browse files
committed
DaleStudy#280 Meeting Rooms II
1 parent 9d968e7 commit fc215a1

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

meeting-rooms-ii/forest000014.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
}

0 commit comments

Comments
 (0)