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. Oracle 找到引起账户锁定的IP

    在ORACLE数据库中,如果没有修改过FAILED_LOGIN_ATTEMPTS的话,默认10次尝试失败后就会锁住用户.此时再登录数据库,就会遇到ORA-28000: the account is l ...

  2. Spark(二)算子详解

    目录 Spark(二)算子讲解 一.wordcountcount 二.编程模型 三.RDD数据集和算子的使用 Spark(二)算子讲解 @ 一.wordcountcount 基于上次的wordcoun ...

  3. mysql运维相关

    1.为什么要分库分表(设计高并发系统的时候,数据库层面该如何设计)?用过哪些分库分表中间件?不同的分库分表中间件都有什么优点和缺点?2.现在有一个未分库分表的系统,未来要分库分表,如何设计才可以让系统 ...

  4. WPF使用转换器(Converter)

    1.作用:可以将源数据和目标数据之间进行特定的转化, 2.定义转换器,需要继承接口IValueConverter [ValueConversion(typeof(int), typeof(string ...

  5. 移动Web前端开发 3移动web开发现状

    移动端的手机浏览器内核一般都是Webkit内核,只需要适配Webkit就可以了 适配问题 屏幕尺寸不一

  6. python文件操作知识点总结:写入篇

    文件写入: 文中的两个变量:f 和 f1(截图时被该死的灯泡遮挡住了) 被称作文件对象 或文件句柄(重口味的叫法,感觉很C++,句子又不是刀子,怎么还带柄?) 以逗号为界,open()方法所依赖的3个 ...

  7. Codeforces Round #584 E2. Rotate Columns (hard version)

    链接: https://codeforces.com/contest/1209/problem/E2 题意: This is a harder version of the problem. The ...

  8. javascript逻辑与(&&)

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. mongod破解版的安装

    navicat for mongodb 12,又叫做navicat 12 for mongodb,是针对mongodb软件而开发的一款管理软件,拥有高效图形用户界面,能够连接本地或远程的MongoDB ...

  10. using来定义类的别名,typedef,#define

    宏定义:其实就是替换作用 #define TRUE 1    //结尾无分号,宏名TRUE,计算机会把所有TRUE替换为1. typedef:定义类的别名 tpyedef unsigned int U ...