class Solution {
public:
vector<Interval> intervalIntersection(vector<Interval>& A, vector<Interval>& B) {
vector<Interval> result;
int i=0;
int j=0;
while(i<A.size()&&j<B.size()) // 用两个指针遍历,计算相交的区间
{
int start=max(A[i].start,B[j].start);
int end=min(A[i].end,B[j].end);
if(start<=end) result.push_back({start,end});
if(A[i].end<B[j].end) i++; // 根据终点的大小,决定移动哪一个指针
else j++;
}
return result;
}
};

Java实现LeetCode #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 解题报告(C++)

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

  3. 【leetcode】986. Interval List Intersections

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

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

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

  5. LC 986. Interval List Intersections

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

  6. Java for LeetCode 057 Insert Interval

    Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessa ...

  7. Java for LeetCode 216 Combination Sum III

    Find all possible combinations of k numbers that add up to a number n, given that only numbers from ...

  8. Java for LeetCode 214 Shortest Palindrome

    Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. ...

  9. Java for LeetCode 212 Word Search II

    Given a 2D board and a list of words from the dictionary, find all words in the board. Each word mus ...

随机推荐

  1. select嵌套问题

    关于sql语句: SELECT COUNT(ID) FROM dbo.N_Order_BusinessBatch WHERE Mobile='15210235082' And CreateTime=( ...

  2. windows定时任务schtasks命令详细解

    SCHTASKS /Create [/S system [/U username [/P [password]]]] [/RU username [/RP password]] /SC schedul ...

  3. 《C程序设计语言》 练习3-3

    问题描述 编写expand(s1,s2),将字符串s1中类似于a-z类的速记符号在字符串s2中扩展为等价的完整列表abc.....xyz.该函数可以处理大小写字母和数字,并可以处理a-b-c,a-z0 ...

  4. IP协议及其它的小弟 ,我保证没人会看的

    IP协议及其它的小弟 IP协议:127.0.0.1就一个32位的标识符.实际上: 类似这样的: 精神小伙慢慢看吧.我赌一包辣条你是不会认真看完的. IP协议的构成 地址解析协议 ARP 前面的叙述中我 ...

  5. 大话Ansible Ad-Hoc命令

    Ansible是一个系列文章,我会尽量以通俗易懂.诙谐幽默的总结方式给大家呈现这些枯燥的知识点,让学习变的有趣一些. Ansible系列博文直达链接:Ansible入门系列 前言 通过前面的文章,大家 ...

  6. C# 数据操作系列 - 11 NHibernate 配置和结构介绍

    0. 前言 今天是NHibernate的第二篇内容,通过上一篇的内容,我们初步了解了NHibernate的创建和使用.这一篇,我继续探索NHibernate背后的秘密.嗯,就是这样. 1. NHibe ...

  7. Unsafe类初探

    Unsafe类是java中非常特别的一个类.它名字就叫做"不安全",提供的操作可以直接读写内存.获得地址偏移值.锁定或释放线程. 通过正常途径是无法获得Unsafe实例的,首先它的 ...

  8. reids不重启切换rdb到aof

    reids不重启切换rdb到aof

  9. Linux(一):VMware安装出现的问题

    目录 1 兼容性问题 2 VMware打卡虚拟机提示"此虚拟机可能已被复制或移动" 1 兼容性问题 问题:VMware Workstation 与 Device/Credentia ...

  10. Java中的集合(三)继承Collection的Queue接口

    Java中的集合(三)继承Collection的Queue接口 一.Queue介绍 Queue接口继承自Collection接口,是Java中定义的一种队列数据结构,元素是有序的(按插入顺序排序),先 ...