merge-in-between-linked-lists very easy approach
/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
class Solution {
    public ListNode mergeInBetween(ListNode list1, int a, int b, ListNode list2) {
        ListNode curr = list1;
        ListNode currfin = list2;
        for(int i= 1;i<a;i++)
            curr=curr.next;
                       
            
        ListNode tmp = curr;
        for(int i = a;i<b+2;i++)
            tmp = tmp.next;
        
        curr.next = list2;
        while(currfin.next!=null){
            currfin=currfin.next;
        }
        currfin.next=tmp;
        
        //currfin.next = tmp;
        return list1;
    }
}
Comments (0)