剑指OFFER----合并两个排序的链表 (js实现)

题目
输入两个单调递增的链表,输出两个链表合成后的链表,当然我们需要合成后的链表满足单调不减规则。

function Merge(pHead1, pHead2) {
    // write code here
    var Head = null;
    if (pHead1 == null || pHead2 == null) {
        return pHead1 || pHead2
    }

    if (pHead1.val <= pHead2.val) {
        Head = pHead1
        Head.next = Merge(pHead1.next, pHead2)

    } else {
        Head = pHead2
        Head.next = Merge(pHead2.next, pHead1)
    }
    return Head

}
点赞