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>,了解了如 ...
随机推荐
- HGOI 20191029pm 题解
Promblem A 小学组 给出一个位运算操作符$\oplus \in \{or , and , xor\}$ ,和$n$个$m$维向量$a_i$,其中$a_{i,j} \in \{0,1\}$. ...
- python拼音库pypinyin库详解
# -*- coding: utf-8 -*- # @Author : FELIX # @Date : 2018/6/30 9:20 from pypinyin import pinyin, lazy ...
- spark实现smote近邻采样
一.smote相关理论 (1). SMOTE是一种对普通过采样(oversampling)的一个改良.普通的过采样会使得训练集中有很多重复的样本. SMOTE的全称是Synthetic Minorit ...
- Okhttp源码分析--基本使用流程分析
Okhttp源码分析--基本使用流程分析 一. 使用 同步请求 OkHttpClient okHttpClient=new OkHttpClient(); Request request=new Re ...
- word 之 插入删除空行
好久没有写程序了.有些手生: 在用C#对word进行直接开发操作过程中,为了文档的美观,我们会插入或删除空行. 1.插入空行的代码很简单. Selection 类型的TypeParagraph()函数 ...
- C++ 学习时的错误记录
1. 关于C++相关的文件扩展名 c++程序中的头文件扩展名包括: .h .hpp .hxx C++程序中源文件的扩展名包括: .cc .cpp .cxx 2.C++程序编译过程 3. 处理错误 4. ...
- 如何修改phpstorm的缓存目录
相信使用phpstorm的人们都被缓存目录的大小困扰过.怎么修改到其它地方呢? 1. 找到 idea.properties 文件,配置信息都在此文件中,F:\Program Files\JetBrai ...
- hotspot 线程状态
- java二进制工具
可以运用jdk工具监控java应用性能,再配合 jmeter 进行了一个长时间的加压,在加压过程中重点关注了系统资源的使用情况 D:\Program Files (x86)\Java\jdk1.8.0 ...
- Dom4j工具j解析XML原理和示例代码
import java.io.File; import java.util.ArrayList; import java.util.Iterator; import java.util.List; i ...