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. 网络爬虫基本概念与Scrapy工具包使用

    Scrapy网络爬虫 Scrapy结构图: Scrapy流动图 图 2-1 1.在D:\Workspace下新建ScrapyTest文件夹,即D:\Workspace\ScrapyTest 2.cd ...

  2. Spring Boot制作启动图案

    SpringBoot在启动时会有一个默认图案的,如果不喜欢可以自己制作一个. 在resources的目录下新建banner.txt文件. 制作图案地址:springboot启动图案定制 通过输入字符串 ...

  3. 【转帖】linux date 显示指定时区的时间 借助TZ 环境变量 export TZ=Asia/Shanghai 或 America/New_York

    linux date 显示指定时区的时间 借助TZ 环境变量 export TZ=Asia/Shanghai 或 America/New_York 2015-02-10 10:58:22 youcha ...

  4. [Xamarin] - 连接 Mac Agent 显示 "couldn't connect to xxxx, please try again" 之解决

    背景 在 VS 2017 的 Xamarin 项目中,配置 Mac Agent 连接到本地虚拟机中的 MacOS 失败. 1. MacOS 已启用远程登陆.2. SSH 可以登陆成功.3. 防火墙已关 ...

  5. (三)spring Security 从数据库中检索用户名和密码

    文章目录 配置 Druid 数据源 数据库 Mapper 文件 自定义 `UserDetailsService` 自定义登陆校验器 `AuthenticationProvider ` 配置 secur ...

  6. 基于TCP的编程

    前提:本文基于Linux系统下的学习 服务器端 1 创建通讯端口,返回socket设备的文件描述符 sfdsocket(2)#include <sys/types.h> /* See NO ...

  7. springboot基础、注解等

    SpringBoot 1.springboot概念 Spring Boot是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置. ...

  8. Spring Boot 集成 Swagger生成接口文档

    目的: Swagger是什么 Swagger的优点 Swagger的使用 Swagger是什么 官网(https://swagger.io/) Swagger 是一个规范和完整的框架,用于生成.描述. ...

  9. nginx修改响应头(可屏蔽后端服务器的信息:IIS,PHP等)

    修改nginx反向代理请求的Header 需要使用到proxy_set_header和add_header指令.其中: proxy_set_header 来自内置模块ngx_http_proxy_mo ...

  10. Eclipse RCP难点:给Command传递参数(Object)

    这个问题网络上没有答案,国外网站上也没有,本人研究了一天,终于搞明白如何实现,实际上是Eclipse RCP的ICommandService本身就已经提供的方法,只是网络上教的都是使用IHandler ...