Re: [LeetCode] 刷到面试 Grind169 C++

楼主: SuiseiLeda (星街雷达)   2023-03-13 15:57:02
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;
}
};
作者: DreaMaker167 (dreamaker)   2023-03-13 15:58:00
大师
楼主: SuiseiLeda (星街雷达)   2023-03-13 15:59:00
我是废物哦
作者: TNPSCG (TNP)   2023-03-13 16:03:00
讨厌pointer怎么不换个语言
作者: dustsstar79 (穆)   2023-03-13 16:15:00
大师
楼主: SuiseiLeda (星街雷达)   2023-03-13 16:24:00
实验室都用c++ㄚ

Links booklink

Contact Us: admin [ a t ] ucptt.com