Time Intersection
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的更多相关文章
- [LeetCode] Intersection of Two Arrays II 两个数组相交之二
Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...
- [LeetCode] Intersection of Two Arrays 两个数组相交
Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...
- [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 ...
- 【leetcode】Intersection of Two Linked Lists
题目简述: Write a program to find the node at which the intersection of two singly linked lists begins. ...
- [LintCode] Intersection of Two Linked Lists 求两个链表的交点
Write a program to find the node at which the intersection of two singly linked lists begins. Notice ...
- LeetCode Intersection of Two Arrays
原题链接在这里:https://leetcode.com/problems/intersection-of-two-arrays/ 题目: Given two arrays, write a func ...
- Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...
- LeetCode Intersection of Two Arrays II
原题链接在这里:https://leetcode.com/problems/intersection-of-two-arrays-ii/ 题目: Given two arrays, write a f ...
- LeetCode 350. Intersection of Two Arrays II
Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...
- LeetCode 349. Intersection of Two Arrays
Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...
随机推荐
- [转帖]重估BAT与华为的云上野心
重估BAT与华为的云上野心 https://www.leiphone.com/news/201910/Z5aLhckqUjCNJ49o.html 本文作者:王刚 2019-10-11 16:19 导语 ...
- Python random模块(以后用到一个再更新一个)
random模块是产生随机数的模块 1.random.random() 这是产生0~1之间一个随机浮点数,但是不会包括1 import random num = 0 while num < 10 ...
- PowerBuilder学习笔记之2PowerScript语言(二)
z教材地址:https://wenku.baidu.com/view/1e82d26925c52cc58ad6be05.html?sxts=1565679996440 2.4数组 声明数组:Integ ...
- 解决warning: Clock skew detected. Your build may be incomplete
原因:机器系统时间与文件时间不一致 解决:更新所有文件的时间后重新编译 find . -type f | xargs -n 5 touch make clean make xargs -n num ...
- [v]Windows下Git安装指南
参考<Git权威指南>安装整理,图书配套网址参见[1] 1. Cygwin下安装配置Git 1. 在Windows下安装配置Git有2种不同的方案 (1)msysGit, (2)Cygwi ...
- ActiveX控件的注册和反注册
原文转自 https://blog.csdn.net/piaopiaopiaopiaopiao/article/details/41649495 ActiveX控件,需要注册之后才能使用. 注意:注册 ...
- 区块链公链分片技术(sharding)方案思维导图
- .net core使用CSRedisCore连接哨兵集群,并用作redis使用分布式缓存。
CSRedisCore是国内大佬出品的一个Redis-Cli-SDK. Github地址:https://github.com/2881099/csredis 使用此插件作为分布式缓存也十分简单. 一 ...
- 从 ASP.NET Core 2.1 迁移到 2.2 踩坑总结
官方迁移文档:https://docs.microsoft.com/zh-cn/aspnet/core/migration/21-to-22?view=aspnetcore-2.2&tabs= ...
- ftl 列表弄成js数组
例子:ftl 列表:bannerViewUrls var arrayBanner=[<#list bannerViewUrls as list>"${list}"< ...