-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1024-VideoStitching.cs
32 lines (28 loc) · 932 Bytes
/
1024-VideoStitching.cs
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
//-----------------------------------------------------------------------------
// Runtime: 88ms
// Memory Usage: 24.3 MB
// Link: https://leetcode.com/submissions/detail/379506299/
//-----------------------------------------------------------------------------
using System;
namespace LeetCode
{
public class _1024_VideoStitching
{
public int VideoStitching(int[][] clips, int T)
{
Array.Sort(clips, (a, b) => a[0].CompareTo(b[0]));
int count = 0;
int start = 0, end = 0;
for (int i = 0; i < clips.Length && start < T; i++)
{
while (i < clips.Length && clips[i][0] <= start)
end = Math.Max(end, clips[i++][1]);
if (start == end) return -1;
count++;
i--;
start = end;
}
return start >= T ? count : -1;
}
}
}