Java | Easy solution | Beats 100%
Intuition\n\n---\n\nJust by iterating list1 we can find out where we need to insert the list2 at appropriate position.   \n# Approach\n\n---\n\n*Remember List s
# Intuition\n\n---\n\nJust by iterating list1 we can find out where we need to insert the list2 at appropriate position.   \n# Approach\n\n---\n\n*Remember List starts from 0th position, so we need to go till ath, and (b+1)th position * \n- Iterate over list1 and find ListNode at ath, (b+1)th position, as aListNode, bListNode.\n- Then switch the next pointers as follows: \n    - aListNode.next = list2 \n    - tail_of_list2.next = bListNode.next\n# Complexity\n\n---\n\n- Time complexity:\nO(M+N)\n\n- Space complexity:\nO(1)\n\n# Code\n```\n/**\n * Definition for singly-linked list.\n * public class ListNode {\n *     int val;\n *     ListNode next;\n *     ListNode() {}\n *     ListNode(int val) { this.val = val; }\n *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n    public ListNode mergeInBetween(ListNode list1, int a, int b, ListNode list2) {\n        ListNode aListNode = null, bListNode = null, dummyNode = null;\n        dummyNode = new ListNode(0, list1);\n        b++;\n        while(dummyNode.next != null) {\n            a--;\n            b--;\n            dummyNode = dummyNode.next;\n            if(a==0){\n                aListNode = dummyNode;\n            }\n            if(b==0) {\n                bListNode = dummyNode;\n                break;\n            }\n        }\n        if(aListNode == null) aListNode = list1;\n        aListNode.next = list2;\n        // find tail of list2\n        while(list2.next!=null){\n            list2 = list2.next;\n        }\n        list2.next=bListNode.next;\n        return list1;\n    }\n}\n```
['Java']