We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f6027a7 commit b66b35eCopy full SHA for b66b35e
meeting-rooms-ii/TonyKim9401.java
@@ -0,0 +1,22 @@
1
+// TC: O(n)
2
+// visit all intervals to compare each of start time
3
+// SC: O(n)
4
+// PQ save all intervals in the worst case
5
+public class Solution {
6
+ public int minMeetingRooms(List<Interval> intervals) {
7
+ if (intervals == null || intervals.isEmpty()) return 0;
8
+
9
+ intervals.sort((a, b) -> a.start - b.start);
10
11
+ PriorityQueue<Integer> endTimes = new PriorityQueue<>();
12
+ endTimes.add(intervals.get(0).end);
13
14
+ for (int i = 1; i < intervals.size(); i++) {
15
+ Interval current = intervals.get(i);
16
+ if (current.start >= endTimes.peek()) endTimes.poll();
17
+ endTimes.add(current.end);
18
+ }
19
20
+ return endTimes.size();
21
22
+}
0 commit comments