题目如下:

你是一名行政助理,手里有两位客户的空闲时间表: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的更多相关文章

  1. 【LeetCode】253. Meeting Rooms II 解题报告(C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 排序+堆 日期 题目地址:https://leetco ...

  2. 【LeetCode】252. Meeting Rooms 解题报告(C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 排序 日期 题目地址:https://leetcode ...

  3. 【LeetCode】621. Task Scheduler 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 公式法 日期 题目地址:https://leetco ...

  4. 【LeetCode】排序 sort(共20题)

    链接:https://leetcode.com/tag/sort/ [56]Merge Intervals (2019年1月26日,谷歌tag复习) 合并区间 Input: [[1,3],[2,6], ...

  5. 【LeetCode】数学(共106题)

    [2]Add Two Numbers (2018年12月23日,review) 链表的高精度加法. 题解:链表专题:https://www.cnblogs.com/zhangwanying/p/979 ...

  6. 【LeetCode】853. Car Fleet 解题报告(Python)

    [LeetCode]853. Car Fleet 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxu ...

  7. 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java

    [LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...

  8. 【Leetcode】Pascal&#39;s Triangle II

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3 ...

  9. 53. Maximum Subarray【leetcode】

    53. Maximum Subarray[leetcode] Find the contiguous subarray within an array (containing at least one ...

随机推荐

  1. opencv的频域滤波

    下面是频域滤波示例程序: 在本程序中,共有五个自定义函数,分别是: 1. myMagnitude(),在该函数中封装了Opencv中的magnitude函数,实现对于复数图像的幅值计算. 2. dft ...

  2. DMA(Direct Memory Access直接存储器访问)总结

    转载于http://blog.csdn.net/peasant_lee/article/details/5594753 DMA一种高速的数据传输操作,允许在外部设备和存储器之间直接读写数据,不需要CP ...

  3. Autumn is deep, alas! I stand on the grass in the shadow of the evergreen trees.

    essence. n. 本质 flush.n. 脸红 v. 刷洗 initiate.v.开始 intrinsic.固执的 mainfest.a.显然的 intuition.n.直觉上的 refrain ...

  4. homestead安装swoole扩展

    配置好ubuntu的国内镜像源并更新 查看php版本,并安装对应php版本的dev sudo apt install php7.2-dev 配置pecl sudo pecl channel-updat ...

  5. 断言(assert)

    断言是编程术语,表示为一些布尔表达式,程序员相信在程序中的某个特定点该表达式值为真,可以在任何时候启用和禁用断言验证,因此可以在测试时启用断言而在部署时禁用断言. 简单点说,断言指的就是,将结果判断说 ...

  6. 深入理解JVM-垃圾回收器

    摘要: JVM垃圾回收器 看完<深入理解JVM>,结合网上资料后根据跟人理解整理出的简洁版,主要关注是什么, 怎么做到的,特点等,没有进入深入剖析,旨在快速了解,具体应用时个人再根据具体点 ...

  7. 使用vue脚手架的项目如何引入JQuery第三方插件

    1:下载jquery npm install jquery --save 2:打开build文件夹下的webpack.base.conf.js文件: 1)在最上方 引入webpack  var web ...

  8. uni-app导航栏配置

    uni-app写app的内容会与沉浸栏重合在一起,写好好多,都是有点问题的,这次终于找到解决的方法了,与大家分享一下 最简单的解决方式就是配置mainfest.json来关闭沉浸式.即通过打开应用的m ...

  9. excle 文件的导入和导出

    //excle 文件导出 public function excel(){ try{ include(BASE_PATH."Excel/PHPExcel.php"); // ech ...

  10. 22_4mybatis——动态SQL

    1.创建maven工程并导入坐标 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE confi ...