Skip to content

Commit ddb366b

Browse files
add 1669
1 parent 992a059 commit ddb366b

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-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+
|1669|[Merge In Between Linked Lists](https://leetcode.com/problems/merge-in-between-linked-lists/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1669.java) ||Medium|LinedList|
1112
|1668|[Maximum Repeating Substring](https://leetcode.com/problems/maximum-repeating-substring/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1668.java) ||Easy|String|
1213
|1664|[Ways to Make a Fair Array](https://leetcode.com/problems/ways-to-make-a-fair-array/)|[Javascript](./javascript/_1664.js) ||Medium|Greedy|
1314
|1663|[Smallest String With A Given Numeric Value](https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1663.java) ||Medium|Greedy|
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.fishercoder.solutions;
2+
3+
import com.fishercoder.common.classes.ListNode;
4+
5+
public class _1669 {
6+
public static class Solution1 {
7+
public ListNode mergeInBetween(ListNode list1, int a, int b, ListNode list2) {
8+
ListNode pre = new ListNode(-1);
9+
ListNode list1Temp = list1;
10+
pre.next = list1Temp;
11+
b -= a;
12+
while (a > 1) {
13+
list1Temp = list1Temp.next;
14+
a--;
15+
}
16+
ListNode tail = list1Temp.next;
17+
list1Temp.next = list2;
18+
while (b > 0) {
19+
tail = tail.next;
20+
b--;
21+
}
22+
int length = 0;
23+
ListNode temp2 = list2;
24+
while (temp2 != null) {
25+
temp2 = temp2.next;
26+
length++;
27+
}
28+
while (length > 0) {
29+
list1Temp = list1Temp.next;
30+
length--;
31+
}
32+
list1Temp.next = tail.next;
33+
return pre.next;
34+
}
35+
}
36+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.common.classes.ListNode;
4+
import com.fishercoder.common.utils.LinkedListUtils;
5+
import com.fishercoder.solutions._1;
6+
import com.fishercoder.solutions._1669;
7+
import org.junit.BeforeClass;
8+
import org.junit.Test;
9+
10+
import static org.junit.Assert.assertArrayEquals;
11+
import static org.junit.Assert.assertEquals;
12+
13+
public class _1669Test {
14+
private static _1669.Solution1 solution1;
15+
private static ListNode list1;
16+
private static ListNode list2;
17+
private static ListNode expected;
18+
private static ListNode actual;
19+
20+
@BeforeClass
21+
public static void setup() {
22+
solution1 = new _1669.Solution1();
23+
}
24+
25+
@Test
26+
public void test1() {
27+
list1 = LinkedListUtils.contructLinkedList(new int[]{0, 1, 2, 3, 4, 5});
28+
list2 = LinkedListUtils.contructLinkedList(new int[]{1000000, 1000001, 1000002});
29+
expected = LinkedListUtils.contructLinkedList(new int[]{0, 1, 2, 1000000, 1000001, 1000002, 5});
30+
actual = solution1.mergeInBetween(list1, 3, 4, list2);
31+
LinkedListUtils.printList(actual);
32+
assertEquals(expected, actual);
33+
}
34+
35+
}

0 commit comments

Comments
 (0)