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. YII2 实现dropDownList 联动事件

    一.视图中 <div class="main-form"> <?php $form = ActiveForm::begin(); ?> <?= $fo ...

  2. 【2017-07-03】CSS实现父级div透明,子集不透明。

    父级背景色 background: rgba(0, 0, 0, 0.5);

  3. 网页报警提示 This page includes a password or credit card input in a non-secure context. A warning has been added to the URL bar. For more information, see https://goo.gl/zmWq3m.

    This page includes a password or credit card input in a non-secure context. A warning has been added ...

  4. WebMvcConfig

    package cn.xx.yy; import java.util.ArrayList;import java.util.HashMap;import java.util.List;import j ...

  5. tomcat配置CA证书后,https的接口url请求很慢,大概率会超时

    背景:项目需要使用websocket长连接,走nginx反向代理会断开,所以决定要直连项目 [websocket连接https需要使用wss] 项目端口: 项目名:biubiu https证书端口: ...

  6. 怎么在vscode里搜索函数

    怎么在vscode里搜索函数?在vsCode编辑器中如何跨文件查找函数的定义? 问题: 比如: 在 a.js中使用 var res = window.unique(arr); 在未知的js文件定义了u ...

  7. django创建路径导航

    路径导航 :         1.怎样设置需要登录但又不需要验证权限的路径 :                 在settings中定义一个列表,列表中以正则的方式放入需要登录但无需验证的权限的项.在 ...

  8. ES6-12.Symbol

    Symbol是ES6新增的原始类型数据,引入的初衷是为了对象可以有永不重复的属性名. 所以属性名可以是字符串外,还可以是Symbol值: const a = Symbol("a") ...

  9. 五十七.分布式ELK平台、ES安装 、 扩展插件 、Kibana安装

    1. ES集群安装 准备1台虚拟机 部署elasticsearch第一个节点 访问9200端口查看是否安装成功   1ELK是日志分析平台,不是一款软件,而是一整套解决方案,是三个软件产品的首字母缩写 ...

  10. js批量下载文件

    ​关于兼容性问题:   <a href="xxx.docx" target='_blank'></a>   下载文件时,这种写法是没有兼容性问题:但是下载图 ...