Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6707b83

Browse files
add 1024
1 parente38f140 commit6707b83

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ _If you like this project, please leave me a star._ ★
390390
|1030|[Matrix Cells in Distance Order](https://leetcode.com/problems/matrix-cells-in-distance-order/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1030.java)||Easy|
391391
|1029|[Two City Scheduling](https://leetcode.com/problems/two-city-scheduling/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1029.java)||Easy|
392392
|1025|[Divisor Game](https://leetcode.com/problems/divisor-game/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1025.java)||Easy|Math, DP, Brainteaser, Game Theory|
393+
|1024|[Video Stitching](https://leetcode.com/problems/video-stitching/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1024.java)||Medium|Array, DP, Greedy|
393394
|1022|[Sum of Root To Leaf Binary Numbers](https://leetcode.com/problems/sum-of-root-to-leaf-binary-numbers/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1022.java)||Easy|
394395
|1021|[Remove Outermost Parentheses](https://leetcode.com/problems/remove-outermost-parentheses/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1021.java)||Easy|
395396
|1020|[Number of Enclaves](https://leetcode.com/problems/number-of-enclaves/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1020.java)||Medium|Graph, DFS, BFS, recursion|
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
packagecom.fishercoder.solutions;
2+
3+
importjava.util.Arrays;
4+
5+
publicclass_1024 {
6+
publicstaticclassSolution1 {
7+
/**
8+
* Greedy
9+
* Time: O(nlogn) where n is the number of clips
10+
* Space: O(1)
11+
*/
12+
publicintvideoStitching(int[][]clips,inttime) {
13+
Arrays.sort(clips, (a,b) ->a[0] ==b[0] ?a[1] -b[1] :a[0] -b[0]);
14+
intcount =0;
15+
intcovered =0;
16+
for (inti =0,start =0;start <time;count++,start =covered) {
17+
for (;i <clips.length &&clips[i][0] <=start;i++) {
18+
covered =Math.max(covered,clips[i][1]);
19+
}
20+
if (start ==covered) {
21+
return -1;
22+
}
23+
}
24+
returncount;
25+
}
26+
}
27+
28+
publicstaticclassSolution2 {
29+
/**
30+
* DP
31+
* Time: ?
32+
* Space: ?
33+
*/
34+
publicintvideoStitching(int[][]clips,inttime) {
35+
//TODO: implement it.
36+
return -1;
37+
}
38+
}
39+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.common.utils.CommonUtils;
4+
importcom.fishercoder.solutions._1024;
5+
importorg.junit.BeforeClass;
6+
importorg.junit.Test;
7+
8+
importstaticorg.junit.Assert.assertEquals;
9+
10+
publicclass_1024Test {
11+
privatestatic_1024.Solution1solution1;
12+
13+
@BeforeClass
14+
publicstaticvoidsetup() {
15+
solution1 =new_1024.Solution1();
16+
}
17+
18+
@Test
19+
publicvoidtest1() {
20+
assertEquals(3,solution1.videoStitching(CommonUtils.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray("[0,2],[4,6],[8,10],[1,9],[1,5],[5,9]"),10));
21+
}
22+
23+
@Test
24+
publicvoidtest2() {
25+
assertEquals(-1,solution1.videoStitching(CommonUtils.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray("[0,1],[1,2]"),5));
26+
}
27+
28+
@Test
29+
publicvoidtest3() {
30+
assertEquals(-1,solution1.videoStitching(CommonUtils.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray("[0,2],[4,8]"),5));
31+
}
32+
33+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp