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 ...
随机推荐
- Redis学习笔记(七) 数据库
Redis 服务器将所有的数据库都保存在服务器状态redisServer结构的db数组中,db数组的每个项都是一个redisDB: struct redisServer{ //一个数组保存着服务器中的 ...
- Angular 初体验
事情起源当初一个简单的截屏然后推流出去的工具,这个工具当初我用winform简单实现了下,然后因公司业余,添加许多程序包,需要自动管理这些程序包,包含下载更新上传等,以及与后台交互,学生老师提醒,自动 ...
- JS异步之宏队列与微队列
1. 原理图 2. 说明 JS 中用来存储待执行回调函数的队列包含 2 个不同特定的列队 宏列队:用来保存待执行的宏任务(回调),比如:定时器回调.DOM 事件回调.ajax 回调 微列队:用来保存待 ...
- Go语言学习目录
第一章 Go环境搭建 1.1 Linux搭建Go环境 1.2 Mac搭建Go环境 1.3 Windows搭建Go环境 第二章 Go语言特性 2.1 Go特征 2.2 Go变量类型 2.3 Go内置函数 ...
- mysql 查询获取排名的方法(绝对有效)
http://blog.csdn.net/k8080880/article/details/11253305 select case when pid=0 then case when @prevTy ...
- POJ3225
题目链接:https://vjudge.net/problem/POJ-3225 解题思路:这道题要是不看题解以本渣新现在的实力确实是做不出来. 以区间为基础建立线段树. 当X=‘U', 将区间T内的 ...
- 【python爬虫】scrapy入门4--添加cookies
(1) settings.py 取消注释:COOKIES_ENABLED = True (2)爬虫xx.py def parse(self, response): c_dic = {自己抓包} # 获 ...
- Docker虚拟机配置手札(centos)
一.Docker只支持CentOS7及以上系统,不支持6.x系统 二.yum安装Docker 1.安装相关环境和设置仓库 yum install -y yum-utils device-mapper- ...
- [Objective-C] 005_Category(类别)
Category的实际作用就是为已有的类来添加方法.为现有的类添加的方法可以先不用实现,在需要的时候再实现也是可以的.在我们的实际代码中如何来实现Category的呢?我们上篇的Person 类为例. ...
- This关键字练习
Account: package com.aff.ex; public class Account { private int id;// 账号 private double balance;// 余 ...