From 9e700ca417c158c60f365a032f91496e0f7bd472 Mon Sep 17 00:00:00 2001 From: ashmichheda Date: Tue, 24 Aug 2021 21:19:14 -0700 Subject: [PATCH 1/2] fix: add solution and testcase for 1669 --- src/main/java/com/fishercoder/solutions/_1669.java | 4 ++++ src/test/java/com/fishercoder/_1669Test.java | 4 ++++ 2 files changed, 8 insertions(+) create mode 100644 src/main/java/com/fishercoder/solutions/_1669.java create mode 100644 src/test/java/com/fishercoder/_1669Test.java diff --git a/src/main/java/com/fishercoder/solutions/_1669.java b/src/main/java/com/fishercoder/solutions/_1669.java new file mode 100644 index 0000000000..0163d33541 --- /dev/null +++ b/src/main/java/com/fishercoder/solutions/_1669.java @@ -0,0 +1,4 @@ +package com.fishercoder.solutions; + +public class _1669 { +} diff --git a/src/test/java/com/fishercoder/_1669Test.java b/src/test/java/com/fishercoder/_1669Test.java new file mode 100644 index 0000000000..0119768d70 --- /dev/null +++ b/src/test/java/com/fishercoder/_1669Test.java @@ -0,0 +1,4 @@ +package com.fishercoder; + +public class _1669Test { +} From 06e4d7e85f7bbe15c6e2de39a82892c43f260c0a Mon Sep 17 00:00:00 2001 From: ashmichheda Date: Tue, 24 Aug 2021 21:24:03 -0700 Subject: [PATCH 2/2] fix: add solution and testcase for 1669 --- .../java/com/fishercoder/solutions/_1669.java | 22 +++++++++++++++ src/test/java/com/fishercoder/_1669Test.java | 27 +++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/src/main/java/com/fishercoder/solutions/_1669.java b/src/main/java/com/fishercoder/solutions/_1669.java index 0163d33541..f378d91037 100644 --- a/src/main/java/com/fishercoder/solutions/_1669.java +++ b/src/main/java/com/fishercoder/solutions/_1669.java @@ -1,4 +1,26 @@ package com.fishercoder.solutions; +import com.fishercoder.common.classes.ListNode; + public class _1669 { + public static class Solution1 { + public ListNode mergeInBetween(ListNode list1, int a, int b, ListNode list2) { + ListNode endList = list1; + ListNode startList = null; + + for (int i = 0; i < b; i++, endList = endList.next) { + if (i == a - 1) { + startList = endList; + } + } + // Connect the startList.next to list2 + startList.next = list2; + while (list2.next != null) { + list2 = list2.next; + } + list2.next = endList.next; + endList.next = null; + return list1; + } + } } diff --git a/src/test/java/com/fishercoder/_1669Test.java b/src/test/java/com/fishercoder/_1669Test.java index 0119768d70..7c01136c63 100644 --- a/src/test/java/com/fishercoder/_1669Test.java +++ b/src/test/java/com/fishercoder/_1669Test.java @@ -1,4 +1,31 @@ package com.fishercoder; +import com.fishercoder.common.classes.ListNode; +import com.fishercoder.solutions._1669; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.util.Arrays; + +import static org.junit.Assert.assertEquals; + public class _1669Test { + private static _1669.Solution1 solution1; + private static ListNode l1; + private static ListNode l2; + private static int a; + private static int b; + + @BeforeClass + public static void setup() { + solution1 = new _1669.Solution1(); + } + @Test + public void test1() { + l1 = ListNode.createSinglyLinkedList(Arrays.asList(0, 1, 2, 3, 4, 5)); + l2 = ListNode.createSinglyLinkedList(Arrays.asList(1000000,1000001,1000002)); + a = 3; + b = 4; + assertEquals(ListNode.createSinglyLinkedList(Arrays.asList(0,1,2,1000000,1000001,1000002,5)), solution1.mergeInBetween(l1, a, b, l2)); + } }