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 ...
随机推荐
- Quartz.NET的简单任务管理类
昨天使用Quartz.NET做了个定时任务的功能,并实现了多个定时任务的功能 下面这个类实现了如下功能: 1.对定时任务进行管理 2.创建定时任务,需要给定时任务一个job的名称 3.判断给定的job ...
- 新手易犯的典型缺陷--C#
这段时间花了点时间整理了几个新手易犯的典型缺陷(专门针对C#的),但是个人的力量毕竟有限缺陷的覆盖面比较窄,有些缺陷的描述也不够准确,这里先贴出来看看能不能集思广益,收集整理出更多的典型缺陷.目标就是 ...
- JavaWeb学习 (十一)————Session
一.Session简单介绍 在WEB开发中,服务器可以为每个用户浏览器创建一个会话对象(session对象),注意:一个浏览器独占一个session对象(默认情况下).因此,在需要保存用户数据时,服务 ...
- 搭建前端监控系统(四)Js截图上报篇
===================================================================== 前端监控系统: DEMO地址 GIT代码仓库地址 ==== ...
- 探秘 Java 热部署三(Java agent agentmain)
前言 让我们继续探秘 Java 热部署.在前文 探秘 Java 热部署二(Java agent premain)中,我们介绍了 Java agent premain.通过在main方法之前通过类似 A ...
- php下载远程图片到本地
在使用 PHP 做简单的爬虫的时候,我们经常会遇到需要下载远程图片的需求,所以下面来简单实现这个需求1:使用curl 比如我们有下面这两张图片: $images = [ 'https://img.al ...
- sublime3安装ctags追踪插件
sublime3经常要用到函数追踪插件,怎做的?下面看安装步骤: 1.安装package control 按快捷键 ctrl+shift+p 2.安装搜索 ctags插件 3.下载ctags可执行程序 ...
- Layui tree 下拉菜单树
1.效果: 2.html 代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8" ...
- homebrew 安装 formula 的不同历史版本——以安装 node 为例
homebrew 安装 formula 的不同历史版本--以安装 node 为例 系统环境 macOS Mojave 10.14 Homebrew 1.8.0 Homebrew/homebrew-co ...
- jenkins无法获取插件的解决办法
很多同学在初次配置Jenkins时,是需要安装一些插件的,但是在可选插件和已安装插件里,全都是空白的. 这是为什么呢? 是因为,Jenkins默认的更新站点服务器在国外,但我们身处天朝,所以这个站点已 ...