-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathvideo-stitching.py
More file actions
38 lines (24 loc) · 894 Bytes
/
Copy pathvideo-stitching.py
File metadata and controls
38 lines (24 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from typing import List
from functools import lru_cache
class Solution:
def videoStitching(self, clips: List[List[int]], T: int) -> int:
clips.sort()
@lru_cache(None)
def dfs(clip: int, prev_clip: int) -> int:
prev_end = clips[prev_clip][1] if prev_clip >= 0 else 0
if prev_end >= T:
return 0
min_clips = len(clips) << 1
if clip == len(clips):
return min_clips
start, end = clips[clip]
if start > prev_end:
return min_clips
if end > prev_end:
min_clips = min(min_clips, dfs(clip + 1, clip) + 1,)
min_clips = min(min_clips, dfs(clip + 1, prev_clip),)
return min_clips
min_clips = dfs(0, -1)
if min_clips > len(clips):
return -1
return min_clips