Skip to content

Commit 8c45c2d

Browse files
authoredJan 25, 2024
Update 1024-video-stitching.js
1 parent 4f95c59 commit 8c45c2d

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
 

‎1024-video-stitching.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,34 @@
1+
/**
2+
* @param {number[][]} clips
3+
* @param {number} time
4+
* @return {number}
5+
*/
6+
const videoStitching = function(clips, time) {
7+
const n = clips.length
8+
if(time === 0) return 0
9+
clips.sort((a, b) => a[0] === b[0] ? b[1] - a[1] : a[0] - b[0])
10+
let res = 0, start = 0, end = 0, nextEnd = 0, idx = 0
11+
12+
while(idx < n) {
13+
nextEnd = end
14+
while(idx < n && clips[idx][0] <= end) {
15+
nextEnd = Math.max(nextEnd, clips[idx][1])
16+
idx++
17+
}
18+
res++
19+
if(nextEnd >= time) return res
20+
else if(nextEnd === end) return -1
21+
else {
22+
end = nextEnd
23+
}
24+
}
25+
26+
return -1
27+
28+
};
29+
30+
// anonther
31+
132
/**
233
* @param {number[][]} clips
334
* @param {number} T

0 commit comments

Comments
 (0)
Please sign in to comment.