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. Laravel dingo,HTTP的请求头(accept)无法携带版本号的解决方法

    Laravel dingo,HTTP的请求头(accept)无法携带版本号的解决方法  2017年9月6日  原创分享  zencodex  使用 Laravel dingo 做api开发时,涉及 A ...

  2. python 中type和object的关系

    转自:https://segmentfault.com/a/1190000008938763 学习python的同学都知道这么几句话 object类是所有新式类的父类. type是所有类的类. 那么t ...

  3. Java进阶知识03 Hibernate的基础配置详解

    1.Hibernate的原理/流程步骤 1.通过Configuration().configure(); 读取并解析hibernate.cfg.xml配置文件,并创建一个configuration对象 ...

  4. 常用C库函数小结

    1. sprintf 原型:int sprintf( char *buffer, const char *format, [ argument] - ); 功能:将格式化后的字符串写在buffer中, ...

  5. mysql中in查询中排序

    mysql中in查询条件的时候,很多时候排序是不规则的,如何按照in里面的条件进行排序呢? mysql中给出了办法,在in后面加order by field,order by field的首个条件是按 ...

  6. 20.Python类型转换,Python数据类型转换函数大全

    虽然 Python 是弱类型编程语言,不需要像 Java 或 C 语言那样还要在使用变量前声明变量的类型,但在一些特定场景中,仍然需要用到类型转换. 比如说,我们想通过使用 print() 函数输出信 ...

  7. TCP输入 之 tcp_data_queue

    tcp_data_queue作用为数据段的接收处理,其中分为多种情况: (1) 无数据,释放skb,返回: (2) 预期接收的数据段,a. 进行0窗口判断:b. 进程上下文,复制数据到用户空间:c. ...

  8. R语言:时间的转化

    一般使用R从数据库导出来的时间数据一般都不是我们能看的懂的(具体是什么格式的我也忘记了),需要做如下转化 as.Date(time,origin = '1970-01-01') 最近从网上爬下来的时间 ...

  9. Nginx开启访问日志记录

    1. vi /etc/nginx/nginx.conf 2.打开 log_format 前的注释 3.Server节点中加入 access_log logs/www_access.log main; ...

  10. logstash的index值可以为中文

    logstash中的 output中 有index属性,表示在elk中的主键标识. 在实际应用中,index的值不能为大写字母,可以是小写字母.数字.下划线.中文. 这里重点强调index为中文时,注 ...