Description

Give two users' ordered online time series, and each section records the user's login time point x and offline time point y. Find out the time periods when both users are online at the same time, and output in ascending order.you need return a list of intervals.

  • We guarantee that the length of online time series meet 1 <= len <= 1e6.
  • For a user's online time series, any two of its sections do not intersect.

Example

Example 1:

Input: seqA = [(1,2),(5,100)], seqB = [(1,6)]
Output: [(1,2),(5,6)]
Explanation: In these two time periods (1,2), (5,6), both users are online at the same time.

Example 2:

Input: seqA = [(1,2),(10,15)], seqB = [(3,5),(7,9)]
Output: []
Explanation: There is no time period, both users are online at the same time.

思路:扫描线
根据每个上线的时间段generate events(time,status)。将events按照时间排序,如果时间相同,下线优先于上线。
扫描排序后的events,如果发现上线event count++,如果count更新后 == 2,说明此时两人同时在线,记录此时的时间。 如果发现下线event count--,如果count更新后变成1,说明从两人同时在线的状态变成了一个人在线。生成这个时间段(prevTime,currTime)并加入结果中。

Time Intersection的更多相关文章

  1. [LeetCode] Intersection of Two Arrays II 两个数组相交之二

    Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...

  2. [LeetCode] Intersection of Two Arrays 两个数组相交

    Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...

  3. [LeetCode] Intersection of Two Linked Lists 求两个链表的交点

    Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...

  4. 【leetcode】Intersection of Two Linked Lists

    题目简述: Write a program to find the node at which the intersection of two singly linked lists begins. ...

  5. [LintCode] Intersection of Two Linked Lists 求两个链表的交点

    Write a program to find the node at which the intersection of two singly linked lists begins. Notice ...

  6. LeetCode Intersection of Two Arrays

    原题链接在这里:https://leetcode.com/problems/intersection-of-two-arrays/ 题目: Given two arrays, write a func ...

  7. Intersection of Two Linked Lists

    Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...

  8. LeetCode Intersection of Two Arrays II

    原题链接在这里:https://leetcode.com/problems/intersection-of-two-arrays-ii/ 题目: Given two arrays, write a f ...

  9. LeetCode 350. Intersection of Two Arrays II

    Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...

  10. LeetCode 349. Intersection of Two Arrays

    Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...

随机推荐

  1. LeetCode 279. 完全平方数(Perfect Squares) 7

    279. 完全平方数 279. Perfect Squares 题目描述 给定正整数 n,找到若干个完全平方数(比如 1, 4, 9, 16, ...)使得它们的和等于 n.你需要让组成和的完全平方数 ...

  2. Zero-shot Learning / One-shot Learning / Few-shot Learning

    Zero-shot Learning / One-shot Learning / Few-shot Learning Learning类型:Zero-shot Learning.One-shot Le ...

  3. js多种去重的方法总结

    第一种是比较常规的方法 思路: 1.构建一个新的数组存放结果 2.for循环中每次从原数组中取出一个元素,用这个元素循环与结果数组对比 3.若结果数组中没有该元素,则存到结果数组中 Array.pro ...

  4. 全能中间件 REST API 使用手册

    全能中间件 REST API 使用手册 Ver:17.6.24 技术支持QQ:64445322 QQ群:339616649    任何第三方应用或网站都可以通过使用开放API为用户提供实时优质的服务. ...

  5. 资深程序员推荐必备书籍 《C语言程序设计》

    当下,IT行业发展日趋迅猛,产值成倍增长,高薪的诱惑更是驱使许多人想要进入IT行业发展.为了使大家更全面理解C语言程序设计,由千锋教研院高教产品研发部编著.清华大学出版社倾情出版的<C语言程序设 ...

  6. react组件懒加载

    组件懒加载方式-:react新增的lazy const Alert = lazy(() => import('./components/alert')); export default func ...

  7. Linux下磁盘分区,格式化以及挂载

    测试环境:VMware Workstation / centos7 1.磁盘分区 (1)易于管理和使用: 比如说我们把磁盘分了sda1.sda2.sda3.sda4盘,我们假设sda1盘为系统盘,其他 ...

  8. Kettle部署笔记

    1.启动脚本(启动job) /u02/www/data-integration/kitchen.sh -file:/u02/www/data-integration/job.kjb -logfile= ...

  9. linux 设置用户组共享文件

    1.首先建立一个名为workgroup的用户组,然后向用户组里面添加两名用户 tom 和liming,并为其设置密码 sudo groupadd workgroup [sudo] lcy 的密码: s ...

  10. VC 中的ATL ActiveX 和 MFC ActiveX 有什么区别

    原文转自 https://www.cnblogs.com/zhwl/archive/2012/11/29/2794509.html ATL是ActiveXTemplateLibrary的缩写,它是一套 ...