Skip to content

Latest commit

 

History

History
20 lines (15 loc) · 610 Bytes

21.md

File metadata and controls

20 lines (15 loc) · 610 Bytes

LeetCode 21 Merge Two Sorted Lists——easy

Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.
Example:
Input: 1->2->4, 1->3->4
Output: 1->1->2->3->4->4

思路:
1、合并两个链表、其实和合并排序是一个道理
2、这里头节点有可能改变、设定一个dummy节点
3、判断谁小、便让谁先插入新链表、当有一个为空时便结束循环
4、直接将之后不为空的另一个链表插入