SOURCE

var mergeTwoLists = function (l1, l2) {
    var l3 = new ListNode(-1);
    var c3 = l3;

    while (l1 !== null && l2 !== null) {
        if (l1.val <= l2.val) {
            c3.next = l1;
            l1 = l1.next;
        } else {
            c3.next = l2;
            l2 = l2.next;
        }
        c3 = c3.next;
    }
    //循环完某一链表后,将另一链表剩下的部分直接加入到l3
    c3.next = (l1 === null) ? l2 : l1;
    return l3.next;

};
console 命令行工具 X clear

                    
>
console