题目描述
blablabla
样例
class Solution {
public:
ListNode* merge(ListNode* l1, ListNode* l2) {
ListNode* head;
auto p = l1;
auto q = l2;
if(!l1) return l2;
if(!l2) return l1;
if(l1->val>l2->val){
head = l2;
q = q->next;
}else{
head = l1;
p = p->next;
}
auto t = head;
while(p&&q){
if(p->val>q->val){
t->next = q;
t = t->next;
q = q->next;
}else{
t->next = p;
t = t->next;
p = p->next;
}
}
if(p) t->next = p;
if(q) t->next = q;
return head;
}
};