ShannonHung / ShannonHung.github.io

2 stars 0 forks source link

LeetCode #21 Merge Two Sorted Lists - 刷題之旅 | Shannon's Blog 🐟 技術 | 生活 | 旅行 #114

Open ShannonHung opened 2 months ago

ShannonHung commented 2 months ago

https://shannonhung.github.io/posts/leetcode-21-merge-two-sorted-lists/

1 題目描述 合併兩個有序的鍊錶,並且返回一個新的鍊錶。新的鍊錶是由兩個鍊錶的節點組成的。 2 解法 跟 leetcode-2-add-two-numbers 很類似,因為它涉及到多個 listNode 的操作,並且將操作結果合併為一個,因此我們可以使用 dummy_head 來幫助我們串接結果。因為他是排序,所以要比較兩個數字的大小,但是我們最怕的是在取listNode的值時發現他是None而