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