其他分享
首页 > 其他分享> > BM4 合并两个排序的链表

BM4 合并两个排序的链表

作者:互联网

 

 

 

 

 

 

 

 

function ListNode(x){
    this.val = x;
    this.next = null;
}
function Merge(pHead1, pHead2)
{
     // write code here
    let cur = new ListNode()
    let dummy = cur
    while(pHead1 && pHead2){
        if(pHead1.val <= pHead2.val) {
            cur.next = pHead1
            pHead1 = pHead1.next
        } else {
            cur.next = pHead2
            pHead2 = pHead2.next
        }
        cur = cur.next
    }
    cur.next = pHead1 ? pHead1 : pHead2
    return dummy.next
}
module.exports = {
    Merge : Merge
};

  

标签:function,ListNode,cur,val,链表,let,pHead1,BM4,排序
来源: https://www.cnblogs.com/fangtoushi/p/16064741.html