1024. Video Stitching
//使用java dfs
public int videoStitching(int[][] clips, int T) {
//bfs
Queue<Integer> queue = new LinkedList<>();
Set<Integer> visited = new HashSet<>();
for (int i = 0;i < clips.length; i ++)
if (clips[i][0] == 0){
queue.offer(clips[i][1]);
queue.offer(1);
visited.add(clips[i][0]* 1000 + clips[i][1]);
}
if (queue.isEmpty())
return -1;
int end = -1, step = -1;
while ( !queue.isEmpty() ){
end = queue.poll();
step = queue.poll();
if (end >= T)
return step;
for (int i = 0; i< clips.length; i++){
if (!visited.contains(clips[i][0]* 1000 + clips[i][1]))
if (end >= clips[i][0]){
queue.offer(clips[i][1]);
queue.offer(step + 1);
visited.add(clips[i][0]* 1000 + clips[i][1]);
}
}
}
return -1;
}
python dp
def videoStitching(self, clips: List[List[int]], T: int) -> int:
#dp[i] 代表 到i结尾时间的最小个数
clips.sort()
n = len(clips)
dp = [float('inf')]* n
if clips[0][0] != 0:
return -1
for i in range(n):
if clips[i][0] == 0:
dp[i] = 1
else:
break
for i in range(n):
for j in range(i):
if dp[j] != float('inf') and clips[j][1] >= clips[i][0] :
dp[i] = min(dp[i], dp[j] + 1)
res = float('inf')
for i in range(n):
if clips[i][1] >= T:
res = min(res, dp[i])
return res if res != float('inf') else - 1
1024. Video Stitching的更多相关文章
- 【leetcode】1024. Video Stitching
题目如下: You are given a series of video clips from a sporting event that lasted Tseconds. These video ...
- 【LeetCode】1024. Video Stitching 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 贪心 日期 题目地址:https://leetcod ...
- Leetcode 1024. Video Stitching
class Solution: def helper(self,l,r,clips)->int: maxL,maxR=0,0 iL,iR=-1,-1 for i,c in enumerate(c ...
- [Swift]LeetCode1024. 视频拼接 | Video Stitching
You are given a series of video clips from a sporting event that lasted T seconds. These video clip ...
- Weekly Contest 131
1021. Remove Outermost Parentheses A valid parentheses string is either empty (""), " ...
- Swift LeetCode 目录 | Catalog
请点击页面左上角 -> Fork me on Github 或直接访问本项目Github地址:LeetCode Solution by Swift 说明:题目中含有$符号则为付费题目. 如 ...
- FFMPEG系列课程(一)打开视频解码器
测试环境:windows10 开发工具:VS2013 从今天开始准备些FFmpeg的系列教程,今天是第一课我们研究下打开视频文件和视频解码器.演示环境在windows上,在Linux上代码也是一样. ...
- HTML5视频标签video
现阶段,我们要在网页中嵌入视频的最可靠最常用的办法是使用Flash,通过使用<object>和<embed>标签,就可以通过浏览器播放swf,flv等格式视频文件,但是前提是浏 ...
- with ffmpeg to encode video for live streaming and for recording to files for on-demand playback
We've been doing some experimentation with ffmpeg to encode video for live streaming and for recordi ...
随机推荐
- gitlab+jenkins=自动化构建
jenkins:运维持续集成工具,靠着丰富的插件挑大梁. gitlab:git代码管理仓库web版,功能强大且丰富. 本文是记录自己工作中从搭建到使用~ 前提是会点git~可以去廖老师的网站学习:ww ...
- Beego学习笔记
Beego学习笔记 Go 路由(Controller) 路由就是根据用户的请求找到需要执行的函数或者controller. Get /v1/shop/nike ShopController Get D ...
- JAVA 面试知识点
参考:https://www.cnblogs.com/java1024/p/8594784.html 反射: JAVA反射机制是在运行状态中, 对于任意一个类,都能够知道这个类的所有属性和方法: 对于 ...
- Windows版本redis高可用方案探究
目录 Windows版本redis高可用方案探究 前言 搭建redis主从 配置主redis-28380 配置从redis-23381 配置从redis-23382 将redis部署为服务 启动red ...
- SpringMVC+jquery.uploadify 上传文件
前言 以前用Asp.net MVC+uploadify上传文件,最近学习SpringMVC,所以就用SpringMVC+uploadify做个上传文件的demo. 刚开始用form表单的方式提交,在C ...
- GridView控件的属性、事件
GridView控件的属性 属性 描述 AllowPaging 指示该控件是否支持分页. AllowSorting 指示该控件是否支持排序. AutoGenerateColumns 指示是否自动地为数 ...
- [android] 调用系统照相机和摄像机
查看系统照相机源码,找到清单文件查看 查看意图过滤器,action是android.media.action.IMAGE_CAPTURE category是android.intent.categor ...
- Java并发编程:synchronized、Lock、ReentrantLock以及ReadWriteLock的那些事儿
目录 前言 synchronized用法 修饰方法 修饰实例方法 修饰静态方法 同步代码块 引出Lock Lock用法 子类:ReentrantLock 读写分离锁:ReadWriteLock Loc ...
- java Spring 各版本jar包下载地址
http://repo.spring.io/simple/libs-release-local/org/springframework/
- 4个错误使用JavaScript数组方法的案例
译者按: 做一个有追求的工程师,代码不是随便写的! 原文: Here's how you can make better use of JavaScript arrays 译者: Fundebug 为 ...