楼主: 
hduek153 (专业打酱油)   
2024-03-20 11:46:31突然心神不宁捏
是不是不妙
快三个月没刷题了感觉要复习了QQ
直接偷懒随便写
https://leetcode.com/problems/merge-in-between-linked-lists
/**
 * 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 pre = new ListNode();
        pre.next = list1;
        ListNode cur = list1;
        for (int i = 0; i < a; i ++) {
            cur = cur.next;
            pre = pre.next;
        }
        for (int i = 0; i < b - a; i++) {
            cur = cur.next;
        }
        ListNode tail = cur.next;
        cur.next = null;
        pre.next = list2;
        cur = list2;
        while (cur != null && cur.next != null) {
            cur = cur.next;
        }
        cur.next = tail;
        return list1;
    }
}