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.

Example 1:

Input: schedule = [[[1,2],[5,6]],[[1,3]],[[4,10]]]
Output: [[3,4]]

Explanation:
There are a total of three employees, and all common
free time intervals would be [-inf, 1], [3, 4], [10, inf].
We discard any intervals that contain inf as they aren't finite.
Example 2:

Input: schedule = [[[1,3],[6,7]],[[2,4]],[[2,5],[9,12]]]
Output: [[5,6],[7,9]]

(Even though we are representing Intervals in the form [x, y], the objects inside are Intervals, not lists or arrays. For example, schedule0.start = 1, schedule0.end = 2, and schedule0[0] is not defined.)

Also, we wouldn't include intervals like [5, 5] in our answer, as they have zero length.

Note:

schedule and schedule[i] are lists with lengths in range [1, 50].
0 <= schedule[i].start < schedule[i].end <= 10^8.

 class Solution {
public List<Interval> employeeFreeTime(List<List<Interval>> schedule) {
List<Interval> res = new ArrayList<>();
List<Interval> times = new ArrayList<>();
for (List<Interval> list : schedule) {
times.addAll(list);
}
Collections.sort(times, ((i1, i2) -> i1.start - i2.start));
Interval pre = times.get();
for (int i = ; i < times.size(); i++) {
Interval cur = times.get(i);
if (cur.start <= pre.end) {
pre.end = cur.end > pre.end ? cur.end : pre.end;
} else {
res.add(new Interval(pre.end, cur.start));
pre = cur;
}
}
return res;
}
}

其实我们可以不用sort,我们可以maintain一个k size的heap, k refers to the number of employees 然后每次从heap里面取一个,和之前的一个进行比较。

Employee Free Time的更多相关文章

  1. Got the Best Employee of the year 2015 Star Award

    Got "The Best Employee of the year 2015 Star Award" from the company, thanks to all that h ...

  2. Netsuite > Employee Record Name维护规则

    Employee Record Name 维护规则 - 在NS系统设计中,默认的Field展现是:First Name, Middle Name, Last Name - 在General Prefe ...

  3. 3.实现一个名为Person的类和它的子类Employee,Employee有两个子类Faculty 和Staff。

    23.实现一个名为Person的类和它的子类Employee,Employee有两个子类Faculty 和Staff. 具体要求如下: (1)Person类中的属性有:姓名name(String类型) ...

  4. 23.实现一个名为Person的类和它的子类Employee,Employee有两个子类Faculty 和Staff。 具体要求如下: (1)Person类中的属性有:姓名name(String类型),地址address(String类型), 电话号码telphone(String类型)和电子邮件地址email(String类型); (2)Employee类中的属性有:办公室office(Stri

    package banking; public class Person { private String name; public String address; public String tel ...

  5. 实现一个名为Person的类和它的子类Employee,Employee有两个子类Faculty 和Staff。

    (1)Person类中的属性有:姓名name(String类型),地址address(String类型), 电话号码telphone(String类型)和电子邮件地址email(String类型): ...

  6. 使用Java 8 Lambda表达式对Employee类进行操作

    1,首先定义Employee类. package coffee.how.to.program.early.objects.chapter15; public class Employee { priv ...

  7. Oracle HRMS API – Create Employee

    -- Create Employee -- ------------------------- DECLARE   lc_employee_number            PER_ALL_PEOP ...

  8. org.hibernate.PropertyNotFoundException: Could not find a getter for employee in class com.itcast.f_hbm_oneToMany.Department

    <hibernate-mapping package="com.itcast.f_hbm_oneToMany"> <class name="Depart ...

  9. LeetCode - 690. Employee Importance

    You are given a data structure of employee information, which includes the employee's unique id, his ...

  10. Spring(五):Spring&Struts2&Hibernate整合后,实现查询Employee信息

    背景: 基于之前两篇文章<Spring(三):Spring整合Hibernate>.<Spring(四):Spring整合Hibernate,之后整合Struts2>,了解了如 ...

随机推荐

  1. jQuery.getJSON(url, [data], [callback])

    jQuery.getJSON(url, [data], [callback]) 概述 通过 HTTP GET 请求载入 JSON 数据. 在 jQuery 1.2 中,您可以通过使用JSONP形式的回 ...

  2. 如何理解JS内的Truthy值和Falsy值

    跟据MDN的术语表解释如下: 在 JavaScript 中,Truthy (真值)指的是在 布尔值 上下文中转换后的值为真的值.所有值都是真值,除非它们被定义为 falsy (即除了 false,0, ...

  3. codevs 1013 求先序排列 2001年NOIP全国联赛普及组 x

                         题目描述 Description 给出一棵二叉树的中序与后序排列.求出它的先序排列.(约定树结点用不同的大写字母表示,长度<=8). 输入描述 Inpu ...

  4. 『HGOI 20190917』Cruise 题解 (计算几何+DP)

    题目概述 在平面直角坐标系的第$1$象限和第$4$象限有$n$个点,其中第$i$个点的坐标为$(x_i,y_i)$,有一个权值$p_i$ 从原点$O(0,0)$出发,不重复的经过一些点,最终走到原点, ...

  5. matlab中setdiff

    源自:http://www.w2bc.com/Article/16709 matlab中setdiff()函数作用:判断2个数组中不同元素 c = setdiff(A, B) 返回在A中有,而B中没有 ...

  6. tail命令:显示文件结尾的内容

    tail 命令和 head 命令正好相反,它用来查看文件末尾的数据,其基本格式如下:tail [选项] 文件名 选项 含义 -n K 这里的 K 指的是行数,该选项表示输出最后 K 行,在此基础上,如 ...

  7. 修改 Idea 终端 Terminal 为 GitBash

    Terminal "C:\Program Files\Git\bin\sh.exe" -login -i

  8. 安卓 API 19 低版本设置自带的圆圈效果

    在 Android API 19 环境下,RadioButton 消除或者自定义自带的圆圈效果的形式来设置: 自定义自身选择图标 android:button="@drawable/sele ...

  9. SolrCloud配置

    一.简介 Apache Solr是基于Lucene的全文搜索引擎.如何让Solr具有容错性和高可用性,SolrCloud可以帮助我们搭建集群,提供分布式索引,以及自动备份.SolrCloud是Solr ...

  10. c++ STL之unordered_set

    unordered_set的特点: 自身值就是主键,所以值唯一并且不可修改 基于hash表的无序排列 unordered_set基于哈希表,是无序的. 在一个 unordered_set 容器中,元素 ...