题解 | #合并两个排序的链表#
合并两个排序的链表
http://www.nowcoder.com/practice/d8b6b4358f774294a89de2a6ac4d9337
this.val = x;
this.next = null;
}
function Merge(pHead1, pHead2)
{
// write code here
let cur = new ListNode(-1)
let head = cur
while(pHead1 && pHead2){
if(pHead1.val <= pHead2.val){
head.next = pHead1
head = head.next
pHead1 = pHead1.next
}
else{
head.next = pHead2
head = head.next
pHead2 = pHead2.next
}
}
if(pHead1){
head.next = pHead1
}else{
head.next = pHead2
}
return cur.next
}
module.exports = {
Merge : Merge
};