Employee Free Time
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的更多相关文章
- 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 ...
- Netsuite > Employee Record Name维护规则
Employee Record Name 维护规则 - 在NS系统设计中,默认的Field展现是:First Name, Middle Name, Last Name - 在General Prefe ...
- 3.实现一个名为Person的类和它的子类Employee,Employee有两个子类Faculty 和Staff。
23.实现一个名为Person的类和它的子类Employee,Employee有两个子类Faculty 和Staff. 具体要求如下: (1)Person类中的属性有:姓名name(String类型) ...
- 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 ...
- 实现一个名为Person的类和它的子类Employee,Employee有两个子类Faculty 和Staff。
(1)Person类中的属性有:姓名name(String类型),地址address(String类型), 电话号码telphone(String类型)和电子邮件地址email(String类型): ...
- 使用Java 8 Lambda表达式对Employee类进行操作
1,首先定义Employee类. package coffee.how.to.program.early.objects.chapter15; public class Employee { priv ...
- Oracle HRMS API – Create Employee
-- Create Employee -- ------------------------- DECLARE lc_employee_number PER_ALL_PEOP ...
- 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 ...
- LeetCode - 690. Employee Importance
You are given a data structure of employee information, which includes the employee's unique id, his ...
- Spring(五):Spring&Struts2&Hibernate整合后,实现查询Employee信息
背景: 基于之前两篇文章<Spring(三):Spring整合Hibernate>.<Spring(四):Spring整合Hibernate,之后整合Struts2>,了解了如 ...
随机推荐
- JVM(八),垃圾回收标记算法
八.垃圾回收标记算法 1.对象被判定成垃圾的标准 没有被其他对象引用 2.判断对象是否为垃圾的算法 (1)引用计数法 优点and缺点 (2)可达性分析算法
- CDOJ 1264 人民币的构造 区间问题+数论
人民币的构造 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submit Status ...
- Tiling_easy version
Tiling_easy version 思路:关于dp这种东西,有一点必须要想明白,就是状态与状态之间的转换关系,就比如说要求5个骨牌的方案数,因为有两种骨牌,那么可以用dp[3]+两个横着的骨牌或者 ...
- Android学习_内容提示器
内容提供器 1. 创建自己的内容提供器 1) 继承ContentProvider类,重写6个方法:onCreate().query().insert().update().delete ...
- HashMap在什么场景下会由哪些内部方法导致线程不安全,至少给出一种场景
一直以来只是知道HashMap是线程不安全的,但是到底HashMap为什么线程不安全,多线程并发的时候在什么情况下可能出现问题? HashMap底层是一个Entry数组,当发生hash冲突的时候,ha ...
- ARTS打卡计划第二周
Algorithms: https://leetcode-cn.com/problems/3sum/ 算法是先排序,然后按照两个数和两边逼中,考虑去重. Review: https://www.inf ...
- 用python绘制趋势图
import matplotlib.pyplot as plt #plt用于显示图片 import matplotlib.image as mping #mping用于读取图片 import date ...
- 【黑马JavaSE】1.2.算术\赋值\比较\逻辑\三元运算符、方法入门、JShell编译器
文章目录 1_1_6_05_算术运算符_四则与取模运算 1_1_6_06_算术运算符_加号的多种 1_1_6_07_算术运算符_自增自减运算 1_1_6_08_赋值运算符 这里挺关键的,为什么一个by ...
- redis宕机时哨兵的处理
https://blog.csdn.net/a67474506/article/details/50435498 redis宕机是的故障处理 重启故障机 sentinel.conf 的配置会改变
- javascript之Screen(屏幕)对象
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...