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

Commit0ee163b

Browse files
authored
Add solution and testcase for 1669 (fishercoder1534#157)
* fix: add solution and testcase for 1669* fix: add solution and testcase for 1669
1 parentea2de74 commit0ee163b

File tree

2 files changed

+38
-7
lines changed

2 files changed

+38
-7
lines changed

‎src/main/java/com/fishercoder/solutions/_1669.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
publicclass_1669 {
66
publicstaticclassSolution1 {
77
publicListNodemergeInBetween(ListNodelist1,inta,intb,ListNodelist2) {
8+
89
ListNodepre =newListNode(-1);
910
ListNodelist1Temp =list1;
1011
pre.next =list1Temp;
@@ -33,4 +34,24 @@ public ListNode mergeInBetween(ListNode list1, int a, int b, ListNode list2) {
3334
returnpre.next;
3435
}
3536
}
37+
publicstaticclassSolution2 {
38+
publicListNodemergeInBetween(ListNodelist1,inta,intb,ListNodelist2) {
39+
ListNodeendList =list1;
40+
ListNodestartList =null;
41+
42+
for (inti =0;i <b;i++,endList =endList.next) {
43+
if (i ==a -1) {
44+
startList =endList;
45+
}
46+
}
47+
// Connect the startList.next to list2
48+
startList.next =list2;
49+
while (list2.next !=null) {
50+
list2 =list2.next;
51+
}
52+
list2.next =endList.next;
53+
endList.next =null;
54+
returnlist1;
55+
}
56+
}
3657
}

‎src/test/java/com/fishercoder/_1669Test.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22

33
importcom.fishercoder.common.classes.ListNode;
44
importcom.fishercoder.common.utils.LinkedListUtils;
5-
importcom.fishercoder.solutions._1;
6-
importcom.fishercoder.solutions._1669;
75
importorg.junit.BeforeClass;
6+
importorg.junit.Test;importorg.junit.BeforeClass;
87
importorg.junit.Test;
9-
10-
importstaticorg.junit.Assert.assertArrayEquals;
11-
importstaticorg.junit.Assert.assertEquals;
8+
importcom.fishercoder.solutions._1669;
129

1310
publicclass_1669Test {
1411
privatestatic_1669.Solution1solution1;
12+
privatestatic_1669.Solution1solution2;
13+
privatestaticListNodel1;
14+
privatestaticListNodel2;
15+
privatestaticinta;
16+
privatestaticintb;
1517
privatestaticListNodelist1;
1618
privatestaticListNodelist2;
1719
privatestaticListNodeexpected;
@@ -20,6 +22,7 @@ public class _1669Test {
2022
@BeforeClass
2123
publicstaticvoidsetup() {
2224
solution1 =new_1669.Solution1();
25+
solution2 =new_1669.Solution2();
2326
}
2427

2528
@Test
@@ -31,5 +34,12 @@ public void test1() {
3134
LinkedListUtils.printList(actual);
3235
assertEquals(expected,actual);
3336
}
34-
35-
}
37+
@Test
38+
publicvoidtest2() {
39+
l1 =ListNode.createSinglyLinkedList(Arrays.asList(0,1,2,3,4,5));
40+
l2 =ListNode.createSinglyLinkedList(Arrays.asList(1000000,1000001,1000002));
41+
a =3;
42+
b =4;
43+
assertEquals(ListNode.createSinglyLinkedList(Arrays.asList(0,1,2,1000000,1000001,1000002,5)),solution2.mergeInBetween(l1,a,b,l2));
44+
}
45+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp