1669.cpp (406B)
1 class Solution { 2 public: 3 ListNode *mergeInBetween(ListNode *list1, int a, int b, ListNode *list2) { 4 ListNode *ap, *bp; 5 a--; 6 for (ap = list1; a; a--, b--) 7 ap = ap->next; 8 for (bp = ap; b; b--) 9 bp = bp->next; 10 ap->next = list2; 11 while (ap->next) 12 ap = ap->next; 13 ap->next = bp->next; 14 return list1; 15 } 16 };