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. js 获取 touch length

    window.addEventListener("touchstart", touchHandler, false); function touchHandler(event){ ...

  2. java中如何补齐汉字字符

    一个汉字相当于两个字符,所以需要输入法的时候切换到[中文全角],中文全角占用2个字符(一个空格),半角占用1个字符

  3. leetcode题目3.无重复字符的最长子串(中等)

    题目描述: 给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度. 示例 1: 输入: "abcabcbb"输出: 3 解释: 因为无重复字符的最长子串是 "a ...

  4. HearthBuddy卡牌无法识别

    界面上无法识别,提示是 [Unidentified card ID :DAL_010][Unidentified card ID :DAL_415] Unidentified card ID :HER ...

  5. mysql 查询锁表,解锁

    //1.查看当前数据库锁表的情况   SELECT * FROM information_schema.INNODB_TRX;   //2.杀掉查询结果中锁表的trx_mysql_thread_id ...

  6. GLSL语法入门

    变量 GLSL的变量命名方式与C语言类似.变量的名称可以使用字母,数字以及下划线,但变量名不能以数字开头,还有变量名不能以gl_作为前缀,这个是GLSL保留的前缀,用于GLSL的内部变量.当然还有一些 ...

  7. Cortex-M3 操作模式与特权等级

    Cortex-M3支持2个模式(Handler模式.线程模式)和2个特权等级(特权级.非特权级). 当处理器处在线程模式时,既可以使用特权级,也可以使用非特权级. 当处理器处在Handler模式时,总 ...

  8. WebService:asp.net类库中添加WebService引用出现问题解决方法

    ylbtech-WebService:asp.net类库中添加WebService引用出现问题解决方法 1.返回顶部 1. 在Web项目内添加WebService的引用是件很简单的事情,今天在类库中添 ...

  9. 运维之思科篇——NAT基础配置

    一. NAT(网络地址转换) 1. 作用:通过将内部网络的私有IP地址翻译成全球唯一的公网IP地址,使内部网络可以连接到互联网等外部网络上. 2. 优点: 节省公有合法IP地址 处理地址重叠 增强灵活 ...

  10. layui弹出层处理(获取、操作弹出层数据等)

    要点: 字符串被渲染为弹窗层之后,回自动转换为DOM,可以使用jq进行各种操作 <!DOCTYPE html> <html> <head> <meta cha ...