Leetcode 253 Meeting Rooms II
1 min readNov 1, 2021
Given an array of meeting time intervals intervals
where intervals[i] = [starti, endi]
, return the minimum number of conference rooms required.
Example 1:
Input: intervals = [[0,30],[5,10],[15,20]]
Output: 2
Example 2:
Input: intervals = [[7,10],[2,4]]
Output: 1
Constraints:
1 <= intervals.length <= 104
0 <= starti < endi <= 106
[Java]
- use array sort to sort the meeting start time
- create a priorityqueue as min heap, peek interval would be the earliest ending time
- offer the first interval, and loop for the rest of intervals
- poll from the priorityqueue(which is the earliest ending time), if the next interval start after the this interval, merge it into the the current one.
- or if the current interval and next interval had overlap time, will need to add another room, add it into the queue
- return the pq.size