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] ...
随机推荐
- Keras中图像维度介绍
报错问题: ValueError: Negative dimension size caused by subtracting 5 from 1 for 'conv2d_1/convolution' ...
- SQLLite日期时间函数
SQLLite包含了如下时间/日期函数:datetime().......................产生日期和时间date()...........................产生日期tim ...
- c语言实现串
串 (string)是由零个或者多个字符组成的有限序列,又称字符串 一般表示为 S=“ a1 a2 a3 a4 . . . . . an” 其中S 是串名,双引号串起来的是串值,(有些书用单 ...
- 以前我对你不够好,我也很难受——CSS篇
1)文字下划线.删除线.定划线 Text-decoration:underline /*下划线*/ Text-decoration:overline /*顶划线*/ Text-decorati ...
- jquery.marquee
http://aamirafridi.com/jquery/jquery-marquee-plugin#examples <script src="/plugins/marquee/j ...
- flutter从入门到精通四
widget Flutter 从 React 中吸取灵感(如果有react的编程经验,会很容易理解flutter),通过现代化框架创建出精美的组件. 它的核心思想是用 widget 来构建你的 UI ...
- sva 基础语法
断言assertion被放在verilog设计中,方便在仿真时查看异常情况.当异常出现时,断言会报警.一般在数字电路设计中都要加入断言,断言占整个设计的比例应不少于30%.以下是断言的语法: 1. S ...
- R_数据操作_高级_04
数学函数: abs(x) 绝对值 sqrt(x) 平方根 ceiling(x) 放回不小于x的最小整数 floor(x) 不小于x的最大整数 trunc(x) 先0方向截取x的整数部分 ...
- nginx日志文件的配置
文章来源 运维公会: nginx日志文件的配置 1.日志介绍 nginx有两种日志,一种是访问日志,一种是错误日志. 访问日志中记录的是客户端对服务器的所有请求. 错误日志中记录的是在访问过程中,因为 ...
- 记一次B类地址子网划分
说明:一般内网地址,没有要求严格的划分之类的.需要按要求严格划分一般都是公网地址 温馨提醒:由于笔者功底不是很深厚,只能说我们保证把数算对用相对简单的方法 现有一个公网ip,B类地址130.3.0.0 ...