• 给一个初始节点赋给root,构建的链表连接在其后,返回时返回root.next
  • 两条链哪个小链接哪个节点,被链接的链后移,直到一条链为空,另一条链直接接在最后
public class Solution {
    public ListNode Merge(ListNode list1,ListNode list2) {
        ListNode root = new ListNode(-1), node = root;

        // 直到一条链为空
        while(list1 != null && list2 != null){
            if(list1.val < list2.val) {
                node.next = list1;
                list1 = list1.next;
            } else {
                node.next = list2;
                list2 = list2.next;
            }
            node = node.next;
        }

        // 剩余连接
        node.next = list1 == null ? list2 : list1;
        return root.next;
    }
}