leetcode1024
- class Solution(object):
- def videoStitching(self, clips: 'List[List[int]]', T: int) -> int:
- li = sorted(clips, key = lambda x: (x[0],x[1]))
- #print(li)
- lens = len(li)
- if li[0][0]!=0:
- return -1
- if li[lens-1][1]<T:
- return -1
- count = 0
- basetag = 0
- i = 0
- while i < len(li):
- if li[i][0]<=basetag:
- if li[i][1]>=T:
- return count + 1
- else:
- i += 1
- else:
- count += 1
- basetag = li[i-1][1]
- if basetag >= T:
- return count
- count += 1
- return count
关键的代码是第3行,将二维数组排序,先按第一个数字从小到大,再按第二个数字从小到大。
设定basetag用于存储之前的剪辑的最大时刻,在开始时刻更晚的剪辑中,寻找开始时间小于上一个剪辑的结束时间的所有剪辑中的,结束时间最晚的一个剪辑。
leetcode1024的更多相关文章
- [Swift]LeetCode1024. 视频拼接 | Video Stitching
You are given a series of video clips from a sporting event that lasted T seconds. These video clip ...
随机推荐
- Tomcat中Url中文乱码解决办法
引自:http://thoughtfly.iteye.com/blog/1533481 默认的tomcat容器如果直接使用get方式在url中传中文时,传到后台接收会是乱码. 乱码问题 原因: tom ...
- chrome不好用
(也是写于很久很久以前) 因为工作的某些原因,我本来想换Google chrome作为默认浏览器,真正用它的时候,才发现它一点都不好用,首先它很多网站不支持或显示不完整,比如新浪邮箱,打开新浪邮箱只显 ...
- redis集群服务启动
1 启动redis服务器 redis-server.exe redis.windows.conf 需要配置config节点的bind ip 2 启动redis集群 开启redis.xx.conf 服务 ...
- 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 ...
- IBM MQ常用命令
常用命令 创建队列管理器crtmqm –q QMgrName-q是指创建缺省的队列管理器删除队列管理器dltmqm QmgrName启动队列管理器strmqm QmgrName如果是启动默认的队列管理 ...
- 做好平衡有多难?谈MMO的职业设计
转自:http://www.gameres.com/804893.html 首先要明确个概念:平衡不是在YY好的职业设计基础上去做调整,而是从游戏设计的开始就要打造一套有标准.可调节的游戏设计框架. ...
- sas 数据集导出到excel
PROC EXPORT DATA= Loan.BOM_FILENAME_2 OUTFILE= "D:\output.xls" DBMS=EXCEL REPLAC ...
- nonlocal和global
获取变量时遵循LEGB原则,修改变量时需要global/nonlocal进行修改 global # global的使用 函数外定义了全局变量: global关键字在函数内会修改全局变量 函数外没定义全 ...
- Linux图形操作与命令行
一.执行命令 通过shell 在哪里输入: 1. 字符界面 2. 终端模拟器程序,如gnome-terminal.konsole (最早的linux是没有图形界面的,只有tty,也就是字符终端.当有了 ...
- HBase脚本命令
1. 脚本使用小结1.开启集群 start-hbase.sh 2.关闭集群 stop-hbase.sh 3.开启/关闭[所有]的regionserver.zookeeper hbase-daemons ...