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(clips):
if c[0]<=l and c[1]>=r:
return 1
if c[0]<=l:
if c[1]-l>maxL:
maxL=c[1]-l
iL=i
if c[1]>=r:
print(r,c[0],c[1],maxR)
if r-c[0]>maxR:
maxR=r-c[0]
iR=i
if iL==-1 or iR==-1:
return -1 new_l=clips[iL][1]
new_r=clips[iR][0]
if clips[iL][0]==clips[iR][0] and clips[iL][1]==clips[iR][1]:
return 1
if new_l>=new_r:
return 2
clips=[c for i,c in enumerate(clips) if i not in (iL,iR)]
return 2+self.helper(new_l,new_r,clips) def videoStitching(self, clips: List[List[int]], T: int) -> int:
return self.helper(0,T,clips)
Leetcode 1024. Video Stitching的更多相关文章
- 【LeetCode】1024. Video Stitching 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 贪心 日期 题目地址:https://leetcod ...
- 【leetcode】1024. Video Stitching
题目如下: You are given a series of video clips from a sporting event that lasted Tseconds. These video ...
- 1024. Video Stitching
//使用java dfs public int videoStitching(int[][] clips, int T) { //bfs Queue<Integer> queue = ne ...
- [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上代码也是一样. ...
- leetcode & lintcode for bug-free
刷题备忘录,for bug-free leetcode 396. Rotate Function 题意: Given an array of integers A and let n to be it ...
- leetcode & lintcode 题解
刷题备忘录,for bug-free 招行面试题--求无序数组最长连续序列的长度,这里连续指的是值连续--间隔为1,并不是数值的位置连续 问题: 给出一个未排序的整数数组,找出最长的连续元素序列的长度 ...
随机推荐
- python学习笔记(二十九)为什么python的多线程不能利用多核CPU
问题:为什么python的多线程不能利用多核CPU,但是咱们在写代码的时候,多线程的确是在并发,而且还比单线程快原因:因为GIL,python只有一个GIL,运行python时,就要拿到这个锁才能执行 ...
- 1.2 Getting Started--Naming Conventions(命名约定)
Ember.js使用一个运行时解析器去连接你的对象而没有很多样板文件.作为一个开发者,如果你把code放到约定好的位置这个解析器会自动工作. 一.The Application 1. 当你 ...
- Django:学习笔记(9)——视图
Django:学习笔记(9)——视图 基础视图 基于函数的视图,我们需要在使用条件语句来判断请求类型,并分支处理.但是在基于类的视图中,我们可以在类中定义不同请求类型的方法来处理相对应的请求. 基于函 ...
- org.apache.ibatis.exceptions.TooManyResultsException的异常排查过程
在查阅测试环境业务日志中的ERROR级别的日志时,发现了有一个Mybatis相关的异常错误org.apache.ibatis.exceptions.TooManyResultsException: E ...
- [LeetCode]83. Remove Duplicates from Sorted List(排序链表去重)
Given a sorted linked list, delete all duplicates such that each element appear only once. For examp ...
- VS2010/MFC编程入门之九(对话框:为控件添加消息处理函数)
创建对话框类和添加控件变量在上一讲中已经讲过,这一讲的主要内容是如何为控件添加消息处理函数. MFC为对话框和控件等定义了诸多消息,我们对它们操作时会触发消息,这些消息最终由消息处理函数处理.比如我们 ...
- la5135 无向图 点-双连通 运用
大白书 P314 #include <iostream> #include <algorithm> #include <string.h> #include < ...
- python: 随机选择
想从一个序列中随机抽取若干元素,或者想生成几个随机数. random 模块有大量的函数用来产生随机数和随机选择元素.比如,要想从一个序列中随机的抽取一个元素,可以使用random.choice() : ...
- Java 对比Vector、ArrayList、LinkedList
①引言 在日常生活中能高效的管理和操作数据是非常重要的.Java提供了强大的集合框架,大大提高了开发者的生产力,今天就了解一下有关集合框架方面的问题. Vector.ArrayList.LinkedL ...
- C++之路
我学习C/C++也有两年了.开始是偏爱C语言和C++的语法特性强大,想用来做游戏开发.在深入学习的同时,逐渐了解到C++可以做很多事.大型项目需要用到运行效率高的C++,虽然运行效率越高,开发效率就要 ...