-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1024_Video_Stitching.cpp
More file actions
44 lines (34 loc) · 1.05 KB
/
1024_Video_Stitching.cpp
File metadata and controls
44 lines (34 loc) · 1.05 KB
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
39
40
41
42
43
44
class Solution {
public:
int videoStitching(vector<vector<int>>& clips, int T) {
int n = clips.size();
int index, curr_high, overall_high;
int count = 0;
sort(clips.begin(), clips.end());
if(clips[0][0] != 0)
return -1;
for(int i = 0; i < n; ++i) {
if(clips[i][0] != 0)
break;
index = i;
curr_high = clips[i][1];
}
overall_high = curr_high;
count++;
int temp_ind;
while(curr_high < T) {
for(int i = index; i < n && clips[i][0] <= clips[index][1]; ++i) {
if(clips[i][1] > curr_high) {
curr_high = clips[i][1];
temp_ind = i;
}
}
index = temp_ind;
count++;
if(curr_high <= overall_high)
return -1;
overall_high = curr_high;
}
return count;
}
};