Lintcode30 Insert Interval solution 题解
来源:互联网 发布:mac系统杀毒软件 编辑:程序博客网 时间:2024/05/16 19:24
【题目描述】
Given a non-overlapping interval list which is sorted by start point.Insert a new interval into it, make sure the list is still in order and non-overlapping (merge intervals if necessary).
给出一个无重叠的按照区间起始端点排序的区间列表。在列表中插入一个新的区间,你要确保列表中的区间仍然有序且不重叠(如果有必要的话,可以合并区间)。
【题目链接】
http://www.lintcode.com/en/problem/insert-interval/
【题目解析】
用pos记录newInterval应该插入的位置。顺序遍历intervals中的元素,若当前interval的end比newInterval的start还小,则将当前interval加入答案,同时pos+1;若比newInterval大,则直接加入答案;若有overlap,则需要merge,newInterval的start取两者间小的,end取两者间大的。最后在pos的位置插入newInterval即可。
【参考答案】
http://www.jiuzhang.com/solutions/insert-interval/
0 0
- Lintcode30 Insert Interval solution 题解
- LeetCode题解:Merge/Insert Interval
- leetcode题解-57. Insert Interval
- LeetCode 57. Insert Interval 题解
- LeetCode 题解(34): Insert Interval
- Insert Interval
- Insert Interval
- Insert Interval
- Insert Interval
- Insert Interval
- Insert Interval
- Insert Interval
- Insert Interval
- Insert Interval
- Insert Interval
- Insert Interval
- Insert Interval
- Insert Interval
- linux-进程间通讯(信号量,共享内存)
- SQL数据库连接失败---错误18456
- 设计模式之策略模式
- There is no Action mapped for namespace [/] and action name [helloWorld] as
- 第1章 需求工程概述
- Lintcode30 Insert Interval solution 题解
- 如何删除WIN10开始菜单里不要的文件夹?
- NS2仿真分析无线网络的攻击防御(1)
- ZOJ 3961 Let's Chat
- 系统的安装
- 安卓开发中Theme.AppCompat.Light的解决方法
- opencv历史代码下载
- tf.contrib.rnn.BasicLSTMCell, tf.contrib.rnn.MultiRNNCell深度解析
- 第三十九章项目六 回文数