题目
We are given a list
schedule
of employees, which represents the working time for each employee.Each employee has a list of non-overlapping
Intervals
, and these intervals are in sorted order.Return the list of finite intervals representing common, positive-length free time for all employees, also in sorted order.
示例1:
1 | Input: schedule = [[[1,2],[5,6]],[[1,3]],[[4,10]]] |
示例2:
1 | Input: schedule = [[[1,3],[6,7]],[[2,4]],[[2,5],[9,12]]] |
提示:
schedule
andschedule[i]
are lists with lengths in range[1, 50]
.0 <= schedule[i].start < schedule[i].end <= 10^8
.
解法
解法一:
先把每个表头放在minHeap中. minHeap按照指向的Interval start排序.
poll出来的就是当前最小start的interval. 如果标记的时间比这个interval的start还小就说明出现了断裂也就是空余时间.
把标记时间增大到这个interval的end, 并且把这个interval所在链表的后一位加入minHeap中.
JAVA
1 | public class Interval { |