LintCode 165合併兩個排序鍊錶

2021-08-03 21:02:49 字數 468 閱讀 6431

題目鏈結

將兩個排序鍊錶合併為乙個新的排序鍊錶

樣例給出1->3->8->11->15->null2->null, 返回1->2->3->8->11->15->null

空間複雜度o(1)

時間複雜度o(m+n) m、n分別為鍊錶l1和鍊錶l2的長度 **

/**

* definition of listnode

* class listnode

* }*/class solution

else

l3 = l3->next;

} if(l1)

l3->next = l1;

if(l2)

l3->next = l2;

return head.next;

}};

Lintcode 165 合併兩個排序鍊錶

我的程式碼如下 def mergetwolists self,l1,l2 if l1 none return l2 if l2 none return l1 res listnode none while l1 and l2 if l1.val l2.val print l1.val res l1 ...

165 合併兩個排序鍊錶

中文english 將兩個排序鍊錶合併為乙個新的排序鍊錶 樣例 1 輸入 list1 null,list2 0 3 3 null 輸出 0 3 3 null 樣例2 輸入 list1 1 3 8 11 15 null,list2 2 null 輸出 1 2 3 8 11 15 null 輸入測試資料...

165 合併兩個排序陣列

原題 您在真實的面試中是否遇到過這個題?是 標籤鍊錶 思路 逐個比較l1與l2的結點,將較小的掛載在結果鍊錶上。小技巧 可以建立乙個資料無效的結點作為標誌頭節點,返回其next。ac definition of singly linked list class listnode class solu...