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>,了解了如 ...
随机推荐
- HZOJ 20190719 那一天她离我而去(图论最小环)
这题算是这场考试里最水的一道题了吧,就是求个最小环,但之前没练过,就在考场上yy出了最短路+次短路的傻逼解法,首先是不会求次短路,其次是这显然不对呀,自己随便想想就可以反驳这种解法. 正解比较神,但是 ...
- Linux下SHA256校验
一.将Hash: SHA256文件和需要检验的文件放在同一个文件夹内 二.$sha256sum -c SHA265 文件 输出: 校验文件:ok
- $\LaTeX$数学公式大全10
$10\ Array\ environment,examples$ $\left( \begin{array}{cc} 2\tau & 7\phi-frac5{12} \\ 3\psi &am ...
- [BZOJ2208]:[Jsoi2010]连通数(暴力 or bitset or 塔尖?)
题目传送门 题目描述 度量一个有向图连通情况的一个指标是连通数,指图中可达顶点对的个数. 在上图中,顶点1可以到达1.2.3.4.5. 顶点2可以到达2.3.4.5. 顶点3可以到达3.4.5. 顶点 ...
- flask登录功能实现的思路
flask登录实现过程思路:前端创建表单,post方法,userno,pwd参数 后端首先创建登录验证函数check(验证函数是指通过request.get来获取前端的userno,pwd.然后将两个 ...
- MySql 时区错误
mysql的时区错误问题: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one ...
- el-mement表单校验-校验失败时自动聚焦到失败的input框
思路:调用input的focus()事件,聚焦到失败的input框上, 问题:如何获取失败的input框,结合element的校验方法,查看可以提供入口的地方 调用this.$refs[formNam ...
- [go]beego获取参数/返回参数
获取前端传来的参数 获取数据并转为对应的类型 - ?id=111&id=122 c.GetInt("id") int,111 - ?id=111&id=122 c. ...
- BFC是什么?有什么作用?
BFC(Block Formatting Context)直译为“块级格式化范围”. 一.常见定位方案 在讲 BFC 之前,我们先来了解一下常见的定位方案,定位方案是控制元素的布局,有三种常见方案: ...
- C# lock 为什么要设置成只读
首先给出MSDN的定义: lock 关键字可以用来确保代码块完成运行,而不会被其他线程中断.这是通过在代码块运行期间为给定对象获取互斥锁来实现的. 先来看看执行过程,代码示例如下: 假设线程A先执行, ...