【leetcode】1272. Remove Interval
题目如下:
Given a sorted list of disjoint
intervals, each intervalintervals[i] = [a, b]represents the set of real numbersxsuch thata <= x < b.We remove the intersections between any interval in
intervalsand the intervaltoBeRemoved.Return a sorted list of
intervalsafter all such removals.Example 1:
Input: intervals = [[0,2],[3,4],[5,7]], toBeRemoved = [1,6]
Output: [[0,1],[6,7]]Example 2:
Input: intervals = [[0,5]], toBeRemoved = [2,3]
Output: [[0,2],[3,5]]Constraints:
1 <= intervals.length <= 10^4-10^9 <= intervals[i][0] < intervals[i][1] <= 10^9
解题思路:区间减法,判断两个区间的位置关系即可。
代码如下:
class Solution(object):
def removeInterval(self, intervals, toBeRemoved):
"""
:type intervals: List[List[int]]
:type toBeRemoved: List[int]
:rtype: List[List[int]]
"""
res = []
for start,end in intervals:
if end <= toBeRemoved[0] or start > toBeRemoved[1]:
res.append([start,end])
elif start == toBeRemoved[0] and end == toBeRemoved[1]:
continue
elif start == toBeRemoved[0] and end < toBeRemoved[1]:
continue
elif start == toBeRemoved[0] and end > toBeRemoved[1]:
res.append([toBeRemoved[1],end])
elif start >= toBeRemoved[0] and end == toBeRemoved[1]:
continue
elif start >= toBeRemoved[0] and end <= toBeRemoved[1]:
continue
elif start >= toBeRemoved[0] and end > toBeRemoved[1]:
res.append([toBeRemoved[1],end])
elif start < toBeRemoved[0] and end == toBeRemoved[1]:
res.append([start,toBeRemoved[0]])
elif start < toBeRemoved[0] and end > toBeRemoved[1]:
res.append([start,toBeRemoved[0]])
res.append([toBeRemoved[1],end])
elif start < toBeRemoved[0] and end < toBeRemoved[1]:
res.append([start, toBeRemoved[0]])
return res
【leetcode】1272. Remove Interval的更多相关文章
- 【LeetCode】402. Remove K Digits 解题报告(Python)
[LeetCode]402. Remove K Digits 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http: ...
- 【LeetCode】722. Remove Comments 解题报告(Python)
[LeetCode]722. Remove Comments 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/remove-c ...
- 【LeetCode】57. Insert Interval [Interval 系列]
LeetCode中,有很多关于一组interval的问题.大体可分为两类: 1.查看是否有区间重叠: 2.合并重叠区间; 3.插入新的区间: 4. 基于interval的其他问题 [ 做题通用的关键 ...
- 【leetcode】 26. Remove Duplicates from Sorted Array
@requires_authorization @author johnsondu @create_time 2015.7.22 18:58 @url [remove dublicates from ...
- 【leetcode】1288. Remove Covered Intervals
题目如下: Given a list of intervals, remove all intervals that are covered by another interval in the li ...
- 【leetcode】1233. Remove Sub-Folders from the Filesystem
题目如下: Given a list of folders, remove all sub-folders in those folders and return in any order the f ...
- 【LeetCode】26. Remove Duplicates from Sorted Array 解题报告(Python&C++&Java)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 双指针 日期 [LeetCode] https:// ...
- 【LeetCode】27. Remove Element 解题报告(Python & Java)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 双指针 记录起始位置 日期 题目地址:https:/ ...
- 【LeetCode】1047. Remove All Adjacent Duplicates In String 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 栈 日期 题目地址:https://leetcode ...
随机推荐
- 记录几个常用的Css样式效果
1.更改字体,图标大小小于12px无效的问题 若我们设置font-size:10px是不会有效果的,需要使用 transform: scale(0.68); 更改字体最小大小 2.设置div边框虚化, ...
- HDU 1203 I NEED A OFFER! (动态规划、01背包、概率)
I NEED A OFFER! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- zk安装管理
参考: https://www.cnblogs.com/yinzhengjie/p/9209319.html 10.52.110.48 bi-kafka-310.52.48.92 bi-kafka-1 ...
- 中国高考志愿填报与职业趋势分析 - ActiveReports 大数据分析报告
中国高考志愿填报与职业趋势分析 1977年中国高考制度恢复,重新开启了人才成长之门.40多年来,高考累积录取人数增长了27倍, 2.28亿人报名,9900万名高素质人才先后通过了中国高等教育的培养,高 ...
- 小菜鸟之oracle数据字典
oracle数据字典 一.数据字典 数据字典是oracle存放有关数据库信息的地方,几乎所有的系统信息和对象信息都可在数据字典中进行查询.数据字典是oracle数据库系统的信息核心,它是一组提供有关数 ...
- 设计模式:策略模式(Stratege)
首先我们需要知道策略模式与状态模式是如此的相似,就犹如一对双胞胎一样.只不过状态模式是通过改变对象内部的状态来帮助对象控制自己的行为,而策略模式则是围绕可以互换的算法来创建成功业务的.两者都可用于解决 ...
- 使用vs工具查看dll依赖(也可查看pyc文件的依赖)
vs工具中有个工具叫dumpin.exe,可以用来查看exe文件.dll文件.pyc文件依赖于哪些dll,从而针对性地去检查具体缺失哪些文件(目前是在装TensorFlow时查看具体需要哪个版本的cu ...
- Jmeter的操作流程
1.1 什么是 JMeter Apache JMeter 是 Apache 组织开发的基于 Java 的压力测试工具.用于对软件做压力测试,它最初被设计用于 Web 应用测试,但后来扩展到其他测试领域 ...
- myBatis+Spring+SpringMVC框架面试题整理
myBatis+Spring+SpringMVC框架面试题整理(一) 2018年09月06日 13:36:01 新新许愿树 阅读数 14034更多 分类专栏: SSM 版权声明:本文为博主原创文章 ...
- Fluent API
fluent api用于onmodelcreating里,可以实现比attribute更强更灵活的配置 public partial class StoreDBContext : DbContext ...