Easy to understand ||Beats 100% O(n)Time complexity java code 🔥🔥🔥
\n\n# Complexity\n- Time complexity:\n- O(n+m)\n\n\n- Space complexity:\n- O(1)\n\n\n# Code\n\n/**\n * Definition for singly-linked list.\n * public class ListN
\n\n# Complexity\n- Time complexity:\n- O(n+m)\n\n\n- Space complexity:\n- O(1)\n\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        int i=0;\n        // CREATE A TEMPORARY NODE FOR LIST1\n        ListNode temp=list1;\n        // TRAVERSE TILL A-1 INDEX TO JOIN IT WITH STARTING NODE OF LIST2\n        while(i<a-1)\n        {\n            temp = temp.next;\n            i++;\n        }\n        i=0;\n        // CREATE A TEMPORARY NODE FOR LIST2\n        ListNode temp2 = list1;\n        // TRAVERSE TILL BTH INDEX TO JOIN  LAST NODE OF LIST2  WITH BTH INDEX\n        while(i<b)\n        {\n            temp2=temp2.next;\n            i++;\n        }\n        ListNode temp3 = list2;\n        // REACH TILL LAST NODE OF LIST2\n        while(temp3.next!=null)\n            temp3=temp3.next;\n        // JOIN RESPECTIVE NODE TO EACH OTHER\n        temp.next = list2;\n`       temp3.next = temp2.next;\n        return list1;\n        \n    }\n}\n```
['Linked List', 'Java']