Created
March 28, 2018 17:19
-
-
Save jianminchen/594a448b199f453046b5f7a4ac9c0cf3 to your computer and use it in GitHub Desktop.
Leetcode 253 meeting room II - line sweep algorithm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | |
For example, | |
Given [[0, 30],[5, 10],[15, 20]], | |
return 2. | |
// time -> counter | |
// time -> start -> +1 counter | |
// time -> finish -> - counter | |
0 -> 1 | |
5 -> 1 | |
10 -> -1 | |
15 -> 1 | |
20 -> -1 | |
30 -> -1 | |
time: O(N logN) - sorting takes O(nlgN) | |
space: O(N) | |
Sweep line approach | |
https://github.com/pllk/cphb/blob/master/book.pdf (p. 275) | |
| | | |
|------------ | |
| ---------------- | |
| ---------- | |
| ----- | |
| | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment