【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 ...
随机推荐
- Flask Bug记录之The innermost block that needs to be closed is 'block'.
源码 <!DOCTYPE html> <title>{% block title %}{% endblock title %} - Flask</title> &l ...
- 知乎Python后端面试总结
一面 写个快速排序热热身,分析一下复杂度,如果不使用额外的空间,应该怎么写? 说一下Flask中g是怎么实现的,原理是什么? 说一下浏览器从输入url到页面渲染的过程,越详细越好: 了解web安全吗? ...
- 二维码生成工具类java版
注意:这里我不提供所需jar包的路径,我会把所有引用的jar包显示出来,大家自行Google package com.net.util; import java.awt.BasicStroke; im ...
- SSM+pagehelper分页
1.maven依赖 <dependency> <groupId>com.github.jsqlparser</groupId> <artifactId> ...
- SSM框架的整合与使用——实现简单的转账系统
一.整合思路 SSM框架即SpringMVC + Spring + MyBati框架集,是一种轻量级的Web开源框架.它们各自在JAVA三层架构中负责的模块如下图所示: 其中,SpringMVC与Sp ...
- Windows安全日志
在运行中输入:eventvwr.msc,即可打开事件日志. 登录类型 描述 2 互动(键盘和屏幕的登录系统) 3 网络(即连接到共享文件夹从其他地方在这台电脑上网络) 4 批处理(即计划任务) 5 服 ...
- Django学习(2.2.1版本)
项目技术重难点分析: 模型层:模型是您的数据唯一而且准确的信息来源.它包含您正在储存的数据的重要字段和行为.一般来说,每一个模型都映射一个数据库表. 每各模型都是一个python的类,这些类继承 d ...
- .net Core 图片验证码 基于SkiaSharp实现
public class ImageCaptcha { /// <summary> /// 干扰线的颜色集合 /// </summary> private List<SK ...
- Hexo折腾记--小白修改新主题
UPDATE 2019.5.28 不好意思我又换了个新主题ARIA啦...这回没有个人定制了 前言 如果您曾经来过我的博客,就会发现我的个人博客(https://rye-catcher.github. ...
- 关于微信小程序返回页面时刷新页面的实现
在小程序开发中,我们通常会遇到这样的需求:提交某个表单成功后跳转该表单详情页面,但是返回时需要跳转回到首页(注意:我这里的首页是提交表单页的前一个页面),而不能再返回提交表单的页面,并且要在首页中刷新 ...