forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_1024.java
39 lines (36 loc) · 1.04 KB
/
_1024.java
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
package com.fishercoder.solutions;
import java.util.Arrays;
public class _1024 {
public static class Solution1 {
/**
* Greedy
* Time: O(nlogn) where n is the number of clips
* Space: O(1)
*/
public int videoStitching(int[][] clips, int time) {
Arrays.sort(clips, (a, b) -> a[0] == b[0] ? a[1] - b[1] : a[0] - b[0]);
int count = 0;
int covered = 0;
for (int i = 0, start = 0; start < time; count++, start = covered) {
for (; i < clips.length && clips[i][0] <= start; i++) {
covered = Math.max(covered, clips[i][1]);
}
if (start == covered) {
return -1;
}
}
return count;
}
}
public static class Solution2 {
/**
* DP
* Time: ?
* Space: ?
*/
public int videoStitching(int[][] clips, int time) {
//TODO: implement it.
return -1;
}
}
}