输入两个递增的链表,单个链表的长度为n,合并这两个链表并使新链表中的节点仍然是递增排序的。
class Solution {
public:
ListNode* Merge(ListNode* pHead1, ListNode* pHead2) {
if(!pHead1)return pHead2;//如果pHead1为空,返回pHead2
if(!pHead2)return pHead1;//如果pHead2为空,返回pHead1
if(pHead1->valval)//比交两链表指针所指值的大小
{
pHead1->next=Merge(pHead1->next,pHead2);//递归调用
return pHead1;
}
else
{
pHead2->next=Merge(pHead2->next,pHead1);
return pHead2;
}
}
};



