使用贪心思想,先按照end排序,然后依次寻找下一个(结束时前最早的)不重叠的区域,这样就得到了数量最多的构成不重叠的区域的数量,再用总数量减去最大不重叠区域的数量,就得到了最少的会引起重叠的区域的数量。

 class Solution:
def eraseOverlapIntervals(self, intervals: 'List[Interval]') -> int:
n = len(intervals)
if n <= 1:
return 0
l = sorted(intervals,key=lambda a:a.end)
pre = l[0]
count = 1
for i in range(1,len(l)):
if l[i].start >= pre.end:
count+=1
pre = l[i] return n-count

leetcode435的更多相关文章

  1. [Swift]LeetCode435. 无重叠区间 | Non-overlapping Intervals

    Given a collection of intervals, find the minimum number of intervals you need to remove to make the ...

随机推荐

  1. STL基础--基本介绍

    为什么要使用C++标准库 /* * 为什么使用C++标准库: * 1. 代码重用,不用重新造轮子 * 2. 效率(快速,且使用更少的资源). 现代C++编译器经常对C++标准库的代码有优化 * 3. ...

  2. Svn过滤

    http://blog.csdn.net/hemingwang0902/article/details/6904205

  3. springboot(三 使用mybatis +springboot 完成简单的增删改查)

    先说一些注解: @EnableAutoConfiguration 可以帮助SpringBoot应用将所有符合条件的@Configuration配置都加载到当前SpringBoot创建并使用的IoC容器 ...

  4. mina2的processor

    processor顾名思义,就是进行IO处理,处理当前session的数据读写,并进行业务处理. 在mina server初始化的时候,会初始化一个processor池,通过NioSocketAcce ...

  5. Ajax的总结

    1.运行Ajax的环境,在服务器上才可以实现他的功能,客户端等别的地方,虽然也可以运行,但是功能一定是不全的,有可能很多东西都不会发生反应: 2.传参 (只写关键步骤)  (必须在服务器上运行) ge ...

  6. Windows和pthread中提供的自旋锁

    Windows和POSIX中都提供了自旋锁,我们也可以通过C++11的atomic来实现自旋锁.那么两者性能上面是什么关系?先引入实现代码: #ifndef __spinlock_h__ #defin ...

  7. C语言强化——字符串(1)

    实现 mystrcpy(), mystrcmp(), mystrcat(), mystrlen() ; #include<stdio.h> void mystrcpy(char *i,ch ...

  8. vultr 上实现高可用冗余浮动公网IP出口(使用BIRD+BGP协议)High Availability on Vultr with Floating IP and BGP

    官方文档: https://www.vultr.com/docs/high-availability-on-vultr-with-floating-ip-and-bgp https://www.vul ...

  9. 使用CacheCloud管理Redis实例

    转载来源:http://www.ywnds.com/?p=10610 一.CacheCloud是什么? 最近在使用CacheCloud管理Redis,所以简单说一下,这里主要说一下我碰到的问题.Cac ...

  10. MySQL--局域网、外网访问MySQL

    一.局域网.外网访问 1. 打开CMD,导航到当前MySQL的bin路径,如下图: 2. 访问MySQL:输入MySQL -u root -p,点击Enter键,即可看到密码输入框: 输入密码,点需E ...