题解 | #合并两个排序的链表#
合并两个排序的链表
http://www.nowcoder.com/practice/d8b6b4358f774294a89de2a6ac4d9337
还可以用递归是真的牛逼
function ListNode(x){
this.val = x;
this.next = null;
}
function Merge(pHead1, pHead2)
{
// write code here
let p=new ListNode(-1)
let res=p
while(pHead1!==null&&pHead2!==null){
if(pHead1.val>=pHead2.val){
p.next=pHead2
pHead2=pHead2.next
}else{
p.next= pHead1
pHead1=pHead1.next
}
p=p.next
}
if(pHead1===null){
p.next=pHead2
}else if(pHead2===null){
p.next=pHead1}
return res.next
}
module.exports = {
Merge : Merge
};