【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 <= 10000 <= intervals[i][0] < intervals[i][1] <= 10^5intervals[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 ...
随机推荐
- centos8自定义目录安装php7.3
1.目录结构 源码目录:/home/werben/pkgsrc/php-7.3.11 安装目录:/home/werben/application/php7.3.11 2.下载php源码 # 官网地址: ...
- python-day5(正式学习)
格式化输出 符合某种输出规范的print函数的应用 第一种方式 使用占位符.漫威里有个人叫斯塔克,他平时站在人堆里(print函数引号内的内容)我们看不出来和其他人有什么异常(print的终端显示), ...
- Python爬虫—requests库get和post方法使用
目录 Python爬虫-requests库get和post方法使用 1. 安装requests库 2.requests.get()方法使用 3.requests.post()方法使用-构造formda ...
- 用shell脚本安装MySQL-5.7.22-官方版本
Install_CentOS7_MySQL57_binary.sh #!/bin/bash MySQL_Package=mysql-5.7.22-linux-glibc2.12-x86_64.tar. ...
- S03_CH02_AXI_DMA PL发送数据到PS
S03_CH02_AXI_DMA PL发送数据到PS 1.1概述 本课程的设计原理分析. 本课程循序渐进,承接<S03_CH01_AXI_DMA_LOOP 环路测试>这一课程,在DATA ...
- 【组成原理】BYTE ME!
题目描述 Parity is an important concept in data transmission. Because the process is not error proof, p ...
- sleep(0)、usleep(0)与sched_yield() 调度
结论: 如果你是为了耗掉一个机器周期 ,那直接asm ("nop") , 如果是为了让权,建议把 所有使用 usleep(0) 换成 sched_yield() ; 最近发现很多 ...
- MySQL 聚合函数(四)检测功能依赖
源自MySQL 5.7 官方手册:12.20.4 Detection of Functional Dependence 本节提供了MySQL检测功能依赖的方式的几个示例.这些示例使用此表示法: {X} ...
- nginx反向代理服务器以及负载均衡,从安装到配置
nginx的具体作用不用细说,很强大,做负载均衡.反向代理服务器解决前端跨域问题等等.下面是nginx的安装过程 首先nginx主要的依赖: pcre. pcre-devel zlib zlib-de ...
- Scala学习十七——类型参数
一.本章要点 类.特质.方法和函数都可以有类型参数 将类型参数放置在名称之后,以方括号括起来 类型界定的语法为T<:UpperBound.T>:LowerBound.T<%ViewB ...