1. class Solution(object):
  2. def videoStitching(self, clips: 'List[List[int]]', T: int) -> int:
  3. li = sorted(clips, key = lambda x: (x[0],x[1]))
  4. #print(li)
  5. lens = len(li)
  6. if li[0][0]!=0:
  7. return -1
  8. if li[lens-1][1]<T:
  9. return -1
  10. count = 0
  11. basetag = 0
  12. i = 0
  13. while i < len(li):
  14. if li[i][0]<=basetag:
  15. if li[i][1]>=T:
  16. return count + 1
  17. else:
  18. i += 1
  19. else:
  20. count += 1
  21. basetag = li[i-1][1]
  22. if basetag >= T:
  23. return count
  24.  
  25. count += 1
  26. return count

关键的代码是第3行,将二维数组排序,先按第一个数字从小到大,再按第二个数字从小到大。

设定basetag用于存储之前的剪辑的最大时刻,在开始时刻更晚的剪辑中,寻找开始时间小于上一个剪辑的结束时间的所有剪辑中的,结束时间最晚的一个剪辑。

leetcode1024的更多相关文章

  1. [Swift]LeetCode1024. 视频拼接 | Video Stitching

    You are given a series of video clips from a sporting event that lasted T seconds.  These video clip ...

随机推荐

  1. Tomcat中Url中文乱码解决办法

    引自:http://thoughtfly.iteye.com/blog/1533481 默认的tomcat容器如果直接使用get方式在url中传中文时,传到后台接收会是乱码. 乱码问题 原因: tom ...

  2. chrome不好用

    (也是写于很久很久以前) 因为工作的某些原因,我本来想换Google chrome作为默认浏览器,真正用它的时候,才发现它一点都不好用,首先它很多网站不支持或显示不完整,比如新浪邮箱,打开新浪邮箱只显 ...

  3. redis集群服务启动

    1 启动redis服务器 redis-server.exe redis.windows.conf 需要配置config节点的bind ip 2 启动redis集群 开启redis.xx.conf 服务 ...

  4. error: Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.ActionButton'.

    引用appcompat 类库提示 error: Error retrieving parent for item: No resource found that  matches the given ...

  5. IBM MQ常用命令

    常用命令 创建队列管理器crtmqm –q QMgrName-q是指创建缺省的队列管理器删除队列管理器dltmqm QmgrName启动队列管理器strmqm QmgrName如果是启动默认的队列管理 ...

  6. 做好平衡有多难?谈MMO的职业设计

    转自:http://www.gameres.com/804893.html 首先要明确个概念:平衡不是在YY好的职业设计基础上去做调整,而是从游戏设计的开始就要打造一套有标准.可调节的游戏设计框架. ...

  7. sas 数据集导出到excel

    PROC EXPORT DATA= Loan.BOM_FILENAME_2      OUTFILE= "D:\output.xls"      DBMS=EXCEL REPLAC ...

  8. nonlocal和global

    获取变量时遵循LEGB原则,修改变量时需要global/nonlocal进行修改 global # global的使用 函数外定义了全局变量: global关键字在函数内会修改全局变量 函数外没定义全 ...

  9. Linux图形操作与命令行

    一.执行命令 通过shell 在哪里输入: 1. 字符界面 2. 终端模拟器程序,如gnome-terminal.konsole (最早的linux是没有图形界面的,只有tty,也就是字符终端.当有了 ...

  10. HBase脚本命令

    1. 脚本使用小结1.开启集群 start-hbase.sh 2.关闭集群 stop-hbase.sh 3.开启/关闭[所有]的regionserver.zookeeper hbase-daemons ...