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 ...
随机推荐
- tensorflow 导入gfile模型文件
with tf.gfile.GFile(os.path.join(self.model_dir, 'ner_model.pb'), 'rb') as f: graph_def = self.tf.Gr ...
- SpringBoot---基本配置
1.首先在pom.xml添加对HTML的相关依赖 /** * pom.xml文件 */ <dependencies> <dependency> <groupId>o ...
- mybatis中动态SQL之trim详解
一. 背景 之前mybatis中<where>.<update>.<if>.<foreach>标签用的多,知道有<trim>这个标签,但很少 ...
- 模块,import,from xxx import xxx
一,模块 模块就是一个包含了python定义和声明的文件,文件名就是模块的名字加上.py后缀,总体来说,import加载的模块一共分成四个通用的类别: 1,使用python编写的py文件 2,已被变异 ...
- HTML DOM querySelector() 方法
Document 对象 实例 获取文档中 id="demo" 的元素: document.querySelector("#demo"); <!DOCTY ...
- scala中的isInstanceOf和asInstanceOf
如果实例化了子类的对象,但是将其赋予了父类类型的变量, 在后续的过程中,又需要将父类类型的变量转换为子类类型的变量,应该如何做? Ø 首先,需要使用isInstanceOf 判断对象是否为指定类的对 ...
- Linux常用基本命令:三剑客命令之-awk内置变量与自定义变量
AWK中,变量分为两种:内置变量与自定义变量. 常见的内置变量有: FS:输入字段分隔符, 默认为空白字符 OFS:输出字段分隔符, 默认为空白字符 RS:输入记录分隔符(输入换行符), 指定输入时的 ...
- cf1130E. Wrong Answer(构造)
题意 题目链接 Sol 对构造一无所知... 题解的方法比较神仙,,设第一个位置为\(-1\),\(S = \sum_{i=1}^n a_i\) 那么我们要让\(N * S - (N - 1) * ( ...
- 【读书笔记】iOS-iOS视频
视频多媒体文件主要是存放视频数据信息,视频数据量要远远大于音频数据文件,而且视频编码和解码算法非常复杂,因此早期的计算机由于CPU处理能力差,要采用视频解压卡硬件支持,视频采集和压缩也要采用硬件卡.按 ...
- vue-cli脚手架之webpack.dev.conf.js
webpack.dev.conf.js 开发环境模式配置文件: 'use strict'//js按照严格模式执行 const utils = require('./utils')//导入utils. ...