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 ...
随机推荐
- 动手实现--AC自动机
Trie树: 把若干个单词按前缀合并就得到一棵树,这棵树称为Trie树.Trie树是有根树,每条边表示一个字符,每个节点表示一个从根到当前节点的唯一路径上的字符依次连接得到的字符串.由于空串是任何串的 ...
- 比较接口(Comparable ,Comparator)及流的聚合操作
Comparable 及 Comparator 的区别 Comparable 一个内比较器,类可以和自己比较 compareTo() 自然比较方法 public interface Comparabl ...
- 初识Page Object
PageObject是UI自动化测试项目开发实践的最佳设计模式之一,它的主要特点体现在对界面交互细节的封装上,使测试用例更加专注于业务的操作,从而提高测试用例的可维护性. 1.认识Page Objec ...
- CentOS 7.1 图形化安装
1.在命令行下输入下面的命令来安装 Gnome 包 sudo yum groupinstall "GNOME Desktop" "Graphical Administr ...
- SpringMVC底层执行原理
一个简单的HelloSpringMVC程序 先在web,xml中注册一个前端控制器(DispatcherServlet) <?xml version="1.0" encodi ...
- 「雕爷学编程」Arduino动手做(14)——倾斜角度模块
37款传感器和模块的提法,在网络上广泛流传,其实Arduino能够兼容的传感器模块肯定是不止37种的.鉴于本人手头积累了一些传感器与模块,依照实践出真知(动手试试)的理念,以学习和交流为目的,这里准备 ...
- Crystal | 水晶方法的七大特征,你了解吗?
本文摘自敏捷开发 20世纪90年代末,Alistair Cockburn提出水晶方法论. 自2001年的敏捷宣言提出以来,以极限编程为首的一系列敏捷方法逐渐走入大众视野,其中就包括水晶方法(Cryst ...
- mysql全方位知识大盘点
一.mysql都有哪些存储引擎?各自的特点是什么? 引擎 事务 锁 主键 索引 外键 数据结构 适用场景 InnoDB 支持 行锁.表锁 必须有主键,没有设置会自动创建 主键索引和数据在一起,其他索引 ...
- HashMap基本介绍
1.HashMap简介(本文是按照JDK1.8进行解析) HashMap位于JDK自带jar包rt.jar的java.util目录下. HashMap是一个散列表,存储的内容是键值对<key,v ...
- Python创建一个简单的区块链
区块链(Blockchain)是一种分布式账本(listributed ledger),它是一种仅供增加(append-only),内容不可变(immutable)的有序(ordered)链式数据结构 ...