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 ...
随机推荐
- flink优化总结
一.高性能Flink SQL优化技巧 1.Group Aggregate优化技巧 开启MicroBatch或MiniBatch(提升吞吐) MicroBatch和MiniBatch都是微批处理,只是微 ...
- JS插件:fullCalendar图解
1.首先看下效果: 官网下载链接 https://fullcalendar.io/download .官方效果图:https://fullcalendar.io/ 2.准备工作,引入对应的 css和 ...
- mp4封装格式各box类型讲解及IBP帧计算
mp4封装格式各box类型讲解及IBP帧计算 目录 mp4封装格式各box类型讲解及IBP帧计算 box ftyp box moov box mvhd box (Movie Header Box) t ...
- ScheduleMaster新特性之延时任务初体验
ScheduleMaster在上个月底更新到了2.0版本,在功能和代码以及文档上都往前跨了很大一步,详细信息可以参考这篇文章:https://www.cnblogs.com/hohoa/p/12772 ...
- Unity3D UGUI Image与父级保持比例缩放
using UnityEngine; using System.Collections; using UnityEngine.UI; public class X_RectAutoSize : Mon ...
- redis的参数解释
include /path/to/local.conf 当有公用配置时,可以采用独立出公共配置文件然后引入的方式达到公共配置unixsocket /tmp/redis.sock 通过socket文件进 ...
- WXML属性一览表
id属性 <view id="xxx"></view> class属性 <view class="xxx"></vie ...
- hdu2243
背单词,始终是复习英语的重要环节.在荒废了3年大学生涯后,Lele也终于要开始背单词了.一天,Lele在某本单词书上看到了一个根据词根来背单词的方法.比如"ab",放在单词前一般表 ...
- HDU2819
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2819 题目大意: 给出一个N*N的0/1矩阵,只能交换整行或者整列,问最少交换多少次可以变成一个主对角 ...
- vue移动端转场动画
vue移动端转场动画 1.介绍:使用vue移动端做项目的时候,为了用户的体验良好,我们需要页面有一种进入和转出的效果 // 在App.vue根组件中 <template> <div ...