class Solution {
public:
ListNode* mergeTwoLists(ListNode* list1, ListNode* list2) {
if(!list1)
return list2;
if(!list2)
return list1;
ListNode *p=list1;
ListNode *q=list2;
ListNode *now=new ListNode;
ListNode *head=now;//创建一个新链表头节点;
while(p&&q)
{
if(p->val<=q->val)
{
now->next=p;
p=p->next;
}
else
{
now->next=q;
q=q->next;
}
now=now->next;
}
now->next=p?p:q;
return head->next;
}
};



