Java实现LeetCode #986 - Interval List Intersections
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的更多相关文章
- Leetcode 986. Interval List Intersections
暴搜.. class Solution(object): def intervalIntersection(self, A: List[Interval], B: List[Interval]) -& ...
- 【LeetCode】986. Interval List Intersections 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 双指针 日期 题目地址:https://leetco ...
- 【leetcode】986. Interval List Intersections
题目如下: Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted ...
- 【leetcode】986. Interval List Intersections (双指针)
You are given two lists of closed intervals, firstList and secondList, where firstList[i] = [starti, ...
- LC 986. Interval List Intersections
Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted order ...
- Java for LeetCode 057 Insert Interval
Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessa ...
- 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 ...
- 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. ...
- 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 ...
随机推荐
- [hdu5387 Clock]时钟夹角问题
题意:给一个时刻,求时针.分钟.秒针三者之间的夹角 思路:确定参照点,求出三者的绝对夹角,然后用差来得到它们之间的夹角,钝角情况用360.减去就行了. #include <map> #in ...
- [hdu5371 Hotaru's problem]最大回文半径
题意:在一个字符串里面找最长的[A][B][A]子串,其中[A][B]是回文串,[A]和[B]的长度相等 思路:[A][B]是回文串,所以[B][A]也是回文串.先预处理出每个点的最大回文半径Ri,枚 ...
- iview tree 绑定数据
官方文档 :https://www.iviewui.com/components/tree 效果图 1 主体分析 <Tree ref="tree" :data="t ...
- Linux --常见Linux目录名称
Linux文件系统结构是从Unix文件结构演进过来的,在Linux文件系统中,通用的文件系统中,通用的目录名用于表示一些常见的功能.如下所示: 目录 用途 / 虚拟目录的根目录,通常不会再这里存储文件 ...
- vue 3.0新特性
参考: https://www.cnblogs.com/Highdoudou/p/9993870.html https://www.cnblogs.com/ljx20180807/p/9987822 ...
- Codeforces1157B(B题)Long Number
B. Long Number You are given a long decimal number aa consisting of nn digits from 11 to 99. You als ...
- ambari hdp ssh链接错误
错误信息: ERROR 2019-09-05 10:29:05,700 NetUtil.py:96 - EOF occurred in violation of protocol (_ssl.c:57 ...
- IntelliJ IDEA 2020.1 取消了auto-import自动导入
Maven 和 Gradle 导入功能更新 v2020.1使得Maven和Gradle更改的导入不再繁琐.首先,我们删除了总是触发的自动导入,以及在更新完脚本之前不断显示并建议导入更新的提示框.取而代 ...
- 王艳 201771010127《面向对象程序设计(java)》第八周学习总结
一:理论部分. 1.接口:Java为了克服单继承的缺点,Java使用了接口,一个类可以实现一个或多接口.(接口不是类,而是对类的一组需求描述,它由常量和一组抽象方法组成) 1)通常,接口名称以able ...
- uniapp打包发版到linux服务器步骤----H5端
最近在写uni-app项目,项目打包部署到服务器后,搞了好一会一直打开是空白页,原来自己有几个地方疏忽了,现把步骤整理一下: 第1步:编辑配置 mainifest.json 文件 tip:运行的基础路 ...