253.Meeting-Rooms-II
253. Meeting Rooms II
题目地址
https://leetcode.com/problems/meeting-rooms-ii/
题目描述
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si < ei), find the minimum number of conference rooms required.
Example 1:
Input: [[0, 30],[5, 10],[15, 20]]
Output: 2
Example 2:
Input: [[7,10],[2,4]]
Output: 1
NOTE: input types have been changed on April 15, 2019. Please reset to default code definition to get new method signature.代码
Approach 1: Priority Queue
Complexity Analysis
Time Complexity: O_(_N_log_N).
There are two major portions that take up time here. One is
sortingof the array that takes O_(_N_log_N) considering that the array consists of N elements.Then we have the
min-heap. In the worst case, all N meetings will collide with each other. In any case we have N add operations on the heap. In the worst case we will have N extract-min operations as well. Overall complexity being (NlogN) since extract-min operation on a heap takes O_(log_N).
Space Complexity: O(_N) because we construct the
min-heapand that can contain _N elements in the worst case as described above in the time complexity section. Hence, the space complexity is O_(_N).
Approach #2 Chronological Ordering
Last updated
Was this helpful?