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 e361e6e commit 6afca23Copy full SHA for 6afca23
Intervals/253_Meeting_Rooms_II.java
@@ -6,19 +6,20 @@ public int minMeetingRooms(int[][] intervals) {
6
7
Arrays.sort(intervals, (i1, i2) -> i1[0] - i2[0]);
8
9
- PriorityQueue<Integer> rooms = new PriorityQueue<>();
+ PriorityQueue<int[]> pq = new PriorityQueue<>((i1, i2) -> i1[1] - i2[1]);
10
11
for (int[] interval : intervals) {
12
- int startTime = interval[0];
13
- int endTime = interval[1];
+ if (!pq.isEmpty()) {
+ int[] endsNext = pq.poll();
14
15
- if (!rooms.isEmpty() && rooms.peek() <= startTime) {
16
- rooms.poll();
+ if (interval[0] < endsNext[1]) {
+ pq.offer(endsNext);
17
+ }
18
}
19
- rooms.offer(endTime);
20
+ pq.offer(interval);
21
22
- return rooms.size();
23
+ return pq.size();
24
25
0 commit comments