当前位置:网站首页>LeetCode 1024 Video Stitching (dp,jump game)
LeetCode 1024 Video Stitching (dp,jump game)
2022-06-11 01:44:00 【_ TCgogogo_】
You are given a series of video clips from a sporting event that lasted time seconds. These video clips can be overlapping with each other and have varying lengths.
Each video clip is described by an array clips where clips[i] = [starti, endi] indicates that the ith clip started at starti and ended at endi.
We can cut these clips into segments freely.
- For example, a clip
[0, 7]can be cut into segments[0, 1] + [1, 3] + [3, 7].
Return the minimum number of clips needed so that we can cut the clips into segments that cover the entire sporting event [0, time]. If the task is impossible, return -1.
Example 1:
Input: clips = [[0,2],[4,6],[8,10],[1,9],[1,5],[5,9]], time = 10 Output: 3 Explanation: We take the clips [0,2], [8,10], [1,9]; a total of 3 clips. Then, we can reconstruct the sporting event as follows: We cut [1,9] into segments [1,2] + [2,8] + [8,9]. Now we have segments [0,2] + [2,8] + [8,10] which cover the sporting event [0, 10].
Example 2:
Input: clips = [[0,1],[1,2]], time = 5 Output: -1 Explanation: We cannot cover [0,5] with only [0,1] and [1,2].
Example 3:
Input: clips = [[0,1],[6,8],[0,2],[5,6],[0,4],[0,3],[6,7],[1,3],[4,7],[1,4],[2,5],[2,6],[3,4],[4,5],[5,7],[6,9]], time = 9 Output: 3 Explanation: We can take clips [0,4], [4,7], and [6,9].
Constraints:
1 <= clips.length <= 1000 <= starti <= endi <= 1001 <= time <= 100
Topic link :https://leetcode.com/problems/video-stitching/
The main idea of the topic : Yes n Intervals , Each section can be cut arbitrarily , Find at least a few intervals to cover [0, time]
Topic analysis : Create a new one nums Array , The length is max(clips[i].r),nums[clips[i].l] = clips[i].r - clips[i].l, After the conversion, the question becomes Jump Game and Jump Game Ⅱ Combination of two questions , Through the first Jump Game Judge whether there is a solution , Re pass Jump Game Ⅱ Solve it
0ms, Time beats 100%
class Solution {
private boolean ok(int[] nums, int time) {
int ma = 0;
for (int i = 0; i < time && ma >= i; i++) {
ma = Math.max(ma, i + nums[i]);
}
return ma >= time;
}
public int videoStitching(int[][] clips, int time) {
int n = 0;
for (int i = 0; i < clips.length; i++) {
n = Math.max(n, clips[i][1]);
}
n++;
int[] nums = new int[n];
for (int i = 0; i < clips.length; i++) {
int l = clips[i][0], r = clips[i][1];
nums[l] = Math.max(nums[l], r - l);
}
if (!ok(nums, time)) {
return -1;
}
int cur = 0, ma = 0, ans = 0;
for (int i = 0; i < time && cur < time; i++) {
ma = Math.max(ma, i + nums[i]);
if (cur == i) {
cur = ma;
ans++;
}
}
return ans;
}
}边栏推荐
- 函数的节流和防抖
- CSRF attack
- Current limiting and download interface request number control
- ROS parameter server
- 焱融看|混合云环境下,如何实现数据湖最优存储解决方案
- Configurable custom implementation 1 Implementation interface, 2 Custom configuration 3 Default configuration
- Daily problem essay | 21.11.29: use resttemplate to call external put request, and prompt '400 bad request'
- Be careful, these hidden "bugs" of "array" to "collection"“
- About mobx
- Classic questions: 01 backpack, complete backpack, multiple backpack, two-dimensional cost Backpack
猜你喜欢
![[path planning] week 1: hodgepodge](/img/80/074b847c6826b306318aeb9866a829.jpg)
[path planning] week 1: hodgepodge

2021-2-14 gephi学习笔记

云呐|PDA无线固定资产盘点管理系统

Yunna Qingyuan fixed assets management and barcode inventory system

2.0、ROS与PX4通信详解

记录打包GoogleChrome浏览器插件

Current limiting and download interface request number control

There is a problem with numpy after CONDA installs pytoch

Implementing MySQL fuzzy search with node and express

1.4PX4程序下载
随机推荐
Introduction to China patent award policy support, with a subsidy of 1million yuan
[path planning] week 1: hodgepodge
How to download web photos
"It looks like robbing tickets but actually robbing money". Don't be fooled by fancy ticket robbing products again and again
CSRF attack
Yunna PDA wireless fixed assets inventory management system
Clean up the broken artifacts data (.lastUpdated files) and reload the project. Problem resolution
【ROS】ROSmsg cakin_ Make compilation error
Sealem Finance打造Web3去中心化金融平台基础设施
Once you know these treasure websites, you can't live without them!!!
項目_基於網絡爬蟲的疫情數據可視化分析
Makefile:1860: recipe for target ‘cmake_ check_ build_ system‘ failed make: *** [cmake_check_build_syst
Classic questions: 01 backpack, complete backpack, multiple backpack, two-dimensional cost Backpack
I was so excited about the college entrance examination in 2022
2021-7-18 ROS笔记-xml语言相关
Shenzhen Nanshan District specialized, special and new enterprise application conditions, with a subsidy of 100000-500000 yuan
Web3 ecological decentralized financial platform sealem Finance
项目_基于网络爬虫的疫情数据可视化分析
How much is the bonus of China Patent Award, with a subsidy of 1million yuan
Implementing MySQL fuzzy search with node and express