Merge Two Sorted Lists easy题
这一次也不会写
是看别人讲解后才写出来的
他妈的指针指针指针脂增
class Solution {
public:
ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) {
if(l1 == NULL){
return l2;
}
if(l2 == NULL){
return l1;
}
ListNode dummy(0);
ListNode *tail = &dummy;
while(l1&&l2){
if(l1->val<l2->val){
tail->next = l1;
l1 = l1->next;
}
else{
tail->next = l2;
l2 = l2->next;
}
tail=tail->next;
}
if(l1){
tail->next = l1;
}
if(l2){
tail->next = l2;
}
return dummy.next;
}
};