Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted order.

Return the intersection of these two interval lists.

(Formally, a closed interval [a, b] (with a <= b) denotes the set of real numbers x with a <= x <= b.  The intersection of two closed intervals is a set of real numbers that is either empty, or can be represented as a closed interval.  For example, the intersection of [1, 3] and [2, 4] is [2, 3].)

class Solution {
public:
vector<Interval> intervalIntersection(vector<Interval>& A, vector<Interval>& B) {
int ai = , bi = ;
vector<Interval> ret;
while(ai < A.size() && bi < B.size()) {
if(A[ai].end < B[bi].start) {
ai++;
continue;
} else if(B[bi].end < A[ai].start) {
bi++;
continue;
}
ret.push_back(Interval(max(A[ai].start, B[bi].start), min(A[ai].end, B[bi].end)));
if(A[ai].end <= B[bi].end) {
ai++;
}else{
bi++;
}
}
return ret;
}
};

LC 986. Interval List Intersections的更多相关文章

  1. Leetcode 986. Interval List Intersections

    暴搜.. class Solution(object): def intervalIntersection(self, A: List[Interval], B: List[Interval]) -& ...

  2. 【leetcode】986. Interval List Intersections

    题目如下: Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted ...

  3. Java实现LeetCode #986 - Interval List Intersections

    class Solution { public: vector<Interval> intervalIntersection(vector<Interval>& A, ...

  4. 【leetcode】986. Interval List Intersections (双指针)

    You are given two lists of closed intervals, firstList and secondList, where firstList[i] = [starti, ...

  5. 【LeetCode】986. Interval List Intersections 解题报告(C++)

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

  6. [Swift]LeetCode986. 区间列表的交集 | Interval List Intersections

    Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted order ...

  7. Interval List Intersections

    Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted order ...

  8. ARTS Challenge- Week 1 (2019.03.25~2019.03.31)

    1.Algorithm - at least one leetcode problem per week(Medium+) 986. Interval List Intersections https ...

  9. 算法与数据结构基础 - 双指针(Two Pointers)

    双指针基础 双指针(Two Pointers)是面对数组.链表结构的一种处理技巧.这里“指针”是泛指,不但包括通常意义上的指针,还包括索引.迭代器等可用于遍历的游标. 同方向指针 设定两个指针.从头往 ...

随机推荐

  1. vuejs开发流程

    https://www.cnblogs.com/yexiaowang/p/8489250.html

  2. ELK6.x_Kafka 安装配置文档

    1. 环境描述 1.1.   环境拓扑 如上图所示:Kafka为3节点集群负责提供消息队列,ES为3节点集群.日志通过logstash或者filebeat传送至Kafka集群,再通过logstash发 ...

  3. Python一些细节

    1.python set() dict() 有序问题,不同版本之间的差异,与Java/C++的对比 https://www.cnblogs.com/niuxichuan/p/11608386.html ...

  4. JavaEE企业面试问题之Java基础部分

    1. Java基础部分 1.1 Java中的方法覆盖(Override)和方法重载(Overload)是什么意思? 重载Overload表示同一个类中可以有多个名称相同的方法,但这些方法的参数列表各不 ...

  5. Jquery实践--精读开篇

    JQuery实践,我已经看了最少三遍了.这里面的很多方法对我的工作很有帮助.但由于不是真的进行前端开发,所以JQuery中的很多功能也没有用到.所以隔一段时间想起,就会发觉,一些东西又忘记了.所以趁这 ...

  6. 001_C#我的第一个串口上位机软件

    (一)首先感谢杜洋工作室 < 入门 C#设计 >带来的视频教学 (二)本次设计从会单片机但是又不会上位机又想搞简单上位机的人群角度提供教程 (三)本次教程的目的是制作普通的串口软件,从而实 ...

  7. pyecharts v1 版本 学习笔记 折线图,面积图

    折线图 折线图 基本demo import pyecharts.options as opts from pyecharts.charts import Line c = ( Line() .add_ ...

  8. Oracle shell监控小脚本

    cat dba_cpu_monitor.sh   ##CPU Monitorh=`hostname`cpu_used=`top -b -d 1 -n 2 | grep Cpu | awk 'NR> ...

  9. 开源分布式中间件 DBLE 快速入门指南

    GitHub:https://github.com/actiontech/dble 官方中文文档:https://actiontech.github.io/dble-docs-cn/ 一.环境准备 D ...

  10. oracle数据库GROUP BY 子句

    1.GROUP BY子句 在SELECT 列表中所有未包含在组函数中的列都应该包含在GROUP BY 子句中. 如下: SELECT deptno,AVG(sal) from emp GROUP BY ...