【leetcode】1229.Meeting Scheduler
题目如下:
你是一名行政助理,手里有两位客户的空闲时间表:slots1 和 slots2,以及会议的预计持续时间 duration,请你为他们安排合适的会议时间。
「会议时间」是两位客户都有空参加,并且持续时间能够满足预计时间 duration 的 最早的时间间隔。
如果没有满足要求的会议时间,就请返回一个 空数组。
「空闲时间」的格式是 [start, end],由开始时间 start 和结束时间 end 组成,表示从 start 开始,到 end 结束。
题目保证数据有效:同一个人的空闲时间不会出现交叠的情况,也就是说,对于同一个人的两个空闲时间 [start1, end1] 和 [start2, end2],要么 start1 > end2,要么 start2 > end1。
解题思路:首先对slots1和slots2分别按start排好序。接下来分别从slots1和slots2中取第一个元素,判断两个元素是否满足会议,如果不满足,则从end较小的元素对应的slots中取后一个元素。以此类推,直到找出符合条件的slot为止。
代码如下:
class Solution(object):
def minAvailableDuration(self, slots1, slots2, duration):
"""
:type slots1: List[List[int]]
:type slots2: List[List[int]]
:type duration: int
:rtype: List[int]
"""
def cmpf(v1,v2):
return v1[0] - v2[0]
slots1.sort(cmp=cmpf)
slots2.sort(cmp=cmpf)
inx1 = inx2 = 0
while inx1 < len(slots1) and inx2 < len(slots2):
item1 = slots1[inx1]
item2 = slots2[inx2]
if item1[0] > item2[1]:
inx2 += 1
elif item1[1] < item2[0]:
inx1 += 1
else:
ms = max(item1[0],item2[0])
me = min(item1[1],item2[1])
if me - ms >= duration:
return [ms,ms+duration]
if item1[1] < item2[1]:
inx1 += 1
else:
inx2 += 1
return []
【leetcode】1229.Meeting Scheduler的更多相关文章
- 【LeetCode】253. Meeting Rooms II 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 排序+堆 日期 题目地址:https://leetco ...
- 【LeetCode】252. Meeting Rooms 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 排序 日期 题目地址:https://leetcode ...
- 【LeetCode】621. Task Scheduler 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 公式法 日期 题目地址:https://leetco ...
- 【LeetCode】排序 sort(共20题)
链接:https://leetcode.com/tag/sort/ [56]Merge Intervals (2019年1月26日,谷歌tag复习) 合并区间 Input: [[1,3],[2,6], ...
- 【LeetCode】数学(共106题)
[2]Add Two Numbers (2018年12月23日,review) 链表的高精度加法. 题解:链表专题:https://www.cnblogs.com/zhangwanying/p/979 ...
- 【LeetCode】853. Car Fleet 解题报告(Python)
[LeetCode]853. Car Fleet 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxu ...
- 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java
[LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...
- 【Leetcode】Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3 ...
- 53. Maximum Subarray【leetcode】
53. Maximum Subarray[leetcode] Find the contiguous subarray within an array (containing at least one ...
随机推荐
- java:Oracle(聚合函数,多表查询,表之间的关系)
1.聚合函数 --max,min,sum,avg,count,nvl(,) -- max:最大值 -- max既能取数字的最大值,也可以取字符串的最大值(英文字母排列顺序),根据场景实际意义来看,最好 ...
- MySQL:添加用户、删除用户、授权、远程访问、修改密码
1.创建用户 #test表示你要建立的用户名,后面的123456表示密码, #localhost限制在固定地址localhost登陆 CREATE USER test@localhost IDENTI ...
- 【VS开发】【智能语音处理】MATLAB 与 音频处理 相关内容摘记
MATLAB 与 音频处理 相关内容摘记 MATLAB 与 音频处理 相关内容摘记 1 MATLAB 音频相关函数 1 MATLAB 处理音频信号的流程 2 音量标准化 2 声道分离合并与组合 3 数 ...
- junction 文件夹做连接到别的分区
加载连接 C:\>junction "C:\Docume~1\Admini~1\LocalS~1\Applic~1\360Chr~1\Chrome\UserDa~1\Default&q ...
- jqueryweui关于switch css与js结合
.invoice_wrapper{ .comm_con{ .weui-switch-cp{ .weui-switch-cp__box{ height:0.4rem; margin:0.25rem 0; ...
- 2019CSP-S游记(真)
本来是考完了的,但是由于江西省的负责人员的不小心(?),江西oier的大部分代码都被删掉了, 所以我们需要重考,想看我之前CSP的游记可以看这个点我.下面是我江西重考的游记: Day0 又集训了一个星 ...
- [转帖]Ubuntu忘记超级用户root密码,重新设置密码
Ubuntu忘记超级用户root密码,重新设置密码 版权声明:本文为博主原创文章,转载必须指明出处. https://blog.csdn.net/weixin_37909391/article/det ...
- sql server CDC报错:超出存储过程、函数、触发器的最大嵌套层数(最大层为32)
sys.sp_MScdc_capture_job RAISERROR(22801, 10, -1) --原本 go sys.sp_MScdc_capture_job; go --修改后 ...
- JVM 堆内存设置原理(转)
堆内存设置 原理 JVM堆内存分为2块:Permanent Space 和 Heap Space. Permanent 即 持久代(Permanent Generation),主要存放的是Java类定 ...
- python 链接mysql 事务
import mysql.connector try: con = mysql.connector.connect( host="localhost", port="33 ...