【leetcode】1288. Remove Covered Intervals
题目如下:
Given a list of intervals, remove all intervals that are covered by another interval in the list. Interval
[a,b)is covered by interval[c,d)if and only ifc <= aandb <= d.After doing so, return the number of remaining intervals.
Example 1:
Input: intervals = [[1,4],[3,6],[2,8]]
Output: 2
Explanation: Interval [3,6] is covered by [2,8], therefore it is removed.Constraints:
1 <= intervals.length <= 1000
0 <= intervals[i][0] < intervals[i][1] <= 10^5
intervals[i] != intervals[j]for alli != j
解题思路:两层循环比较一下,用字典记录可以被删除掉的元素的下标。
代码如下:
class Solution(object):
def removeCoveredIntervals(self, intervals):
"""
:type intervals: List[List[int]]
:rtype: int
"""
dic = {}
for i in range(len(intervals)):
for j in range(i+1,len(intervals)):
if i == j :continue
if intervals[i][0] <= intervals[j][0] and intervals[i][1] >= intervals[j][1]:
dic[j] = 1
elif intervals[i][0] >= intervals[j][0] and intervals[i][1] <= intervals[j][1]:
dic[i] = 1
return len(intervals) - len(dic)
【leetcode】1288. Remove Covered Intervals的更多相关文章
- 【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】Insert Interval & Merge Intervals
		Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessa ... 
- 【leetcode】 26. Remove Duplicates from Sorted Array
		@requires_authorization @author johnsondu @create_time 2015.7.22 18:58 @url [remove dublicates from ... 
- 【leetcode】1272. Remove Interval
		题目如下: Given a sorted list of disjoint intervals, each interval intervals[i] = [a, b] represents the ... 
- 【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 ... 
随机推荐
- GrapeCity Documents (服务端文档API组件) V3.0 正式发布
			近日,葡萄城GrapeCity Documents(服务端文档API组件)V3.0 正式发布! 该版本针对 Excel 文档.PDF 文档和 Word 文档的 API 全面更新,加入了用于生成 Exc ... 
- Java静态代理与动态代理实现
			一.什么是代理 代理是一种设计模式,它提供了一种通过代理访问目标对象的方式.在应用代理之前,我们调用对象的过程如下: 客户端直接调用对象并获取返回值.而应用了代理之后,我们调用对象的过程变成如下: 客 ... 
- Photon Server LoadBalancing搭建
			准备:申请3台Windows虚拟机. 3台虚拟机上都部署上Photon Server. 一.主虚拟机上部署MasterServer. (1)在第一台虚拟机中,部署的Photon Server目目录下找 ... 
- js Indexof的用法
			JavaScript中indexOf()函数 JavaScript中indexOf()函数方法返回一个整数值,指出 String 对象内子字符串的开始位置.如果没有找到子字符串,则返回 -1.如果 ... 
- 安装笔记, caffe 、 opencv等
			1. 1.1 opencv static linux mkdir build & cd build cmake .. -LH 这句话用来查看编译选项 如果不知道编译啥 可以用这个查看一下 ... 
- R 读取xls/xlsx文件
			包readxl install.packages('readxl',repois='https://mirrors.utsc.edu.cn/CRAN/) library(readxl) # read_ ... 
- 5.Servlet 对象(request-response)
			/*ServletResponse*/ /*responese常见应用*/ 1.向客户端输出中文数据 (分别以OutputStream 和 PrintWriter输出) 2.文件下载和中文文件的下载 ... 
- vue-element-admin 之改变登录界面input的光标颜色
			前话:用框架原有的login更改而不重写的话,恰好当你input背景设置成白色的时候,光标会找不到=>原因:原框架的光标颜色是#fff 操作更改光标颜色: 找到src/views/login/i ... 
- VTORRAAYY ws+tls+nginx config
			# nginx conf partal location /haha { proxy_redirect off; # the prot should same with config v2*** pr ... 
- kubernetes之pod生命周期,pod重启策略, 镜像拉取策略
			pod声明周期(状态):pending , running, succeeded, failed, unknown 挂起(Pending):Pod 已被 Kubernetes 系统接受,但有一个或者多 ... 
