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

Commitc1aa2f7

Browse files
add 1640
1 parent838b680 commitc1aa2f7

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1640|[Check Array Formation Through Concatenation](https://leetcode.com/problems/check-array-formation-through-concatenation/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1640.java)||Easy|Array, Sort|
1112
|1637|[Widest Vertical Area Between Two Points Containing No Points](https://leetcode.com/problems/widest-vertical-area-between-two-points-containing-no-points/)|[Javascript](./javascript/_1637.js)|| Medium| Sort|
1213
|1636|[Sort Array by Increasing Frequency](https://leetcode.com/problems/sort-array-by-increasing-frequency/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1636.java)||Easy|Array, Sort|
1314
|1630|[Arithmetic Subarrays](https://leetcode.com/problems/arithmetic-subarrays/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1630.java)||Medium|Sort|
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
packagecom.fishercoder.solutions;
2+
3+
publicclass_1640 {
4+
publicstaticclassSolution1 {
5+
publicbooleancanFormArray(int[]arr,int[][]pieces) {
6+
for (int[]piece :pieces) {
7+
intfirst =piece[0];
8+
intindex =findIndex(arr,first);
9+
if (index == -1) {
10+
returnfalse;
11+
}
12+
inti =0;
13+
for (intj =index;i <piece.length &&j <arr.length;i++,j++) {
14+
if (arr[j] !=piece[i]) {
15+
returnfalse;
16+
}
17+
}
18+
if (i !=piece.length) {
19+
returnfalse;
20+
}
21+
}
22+
returntrue;
23+
}
24+
25+
privateintfindIndex(int[]arr,intkey) {
26+
for (inti =0;i <arr.length;i++) {
27+
if (arr[i] ==key) {
28+
returni;
29+
}
30+
}
31+
return -1;
32+
}
33+
}
34+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.solutions._1640;
4+
importorg.junit.BeforeClass;
5+
importorg.junit.Test;
6+
7+
importstaticorg.junit.Assert.assertEquals;
8+
9+
publicclass_1640Test {
10+
privatestatic_1640.Solution1solution1;
11+
privatestaticint[]arr;
12+
privatestaticint[][]pieces;
13+
14+
@BeforeClass
15+
publicstaticvoidsetup() {
16+
solution1 =new_1640.Solution1();
17+
}
18+
19+
@Test
20+
publicvoidtest1() {
21+
arr =newint[]{85};
22+
pieces =newint[][]{{85}};
23+
assertEquals(true,solution1.canFormArray(arr,pieces));
24+
}
25+
26+
@Test
27+
publicvoidtest2() {
28+
arr =newint[]{91,4,64,78};
29+
pieces =newint[][]{{78}, {4,64}, {91}};
30+
assertEquals(true,solution1.canFormArray(arr,pieces));
31+
}
32+
33+
@Test
34+
publicvoidtest3() {
35+
arr =newint[]{49,18,16};
36+
pieces =newint[][]{{16,18,49}};
37+
assertEquals(false,solution1.canFormArray(arr,pieces));
38+
}
39+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp