LeetCode 21 - Merge Two Sorted Lists
Difficulty: easy
Problem Description
English (Merge Two Sorted Lists)
You are given the heads of two sorted linked lists list1
and list2
.
Merge the two lists in a one sorted list. The list should be made by splicing together the nodes of the first two lists.
Return the head of the merged linked list.
Example 1:
graph LR
node11((1))
node12((2))
node13((4))
node11 -----> node12 -----> node13
node21((1))
node22((3))
node23((4))
node21 -------> node22 -----> node23
node31((1))
node32((1))
node33((2))
node34((3))
node35((4))
node36((4))
node31 ---> node32 ---> node33 ---> node34 ---> node35 ---> node36
1 |
|
Example 2:
1 |
|
Example 3:
1 |
|
Constraints:
- The number of nodes in both lists is in the range
[0, 50]
. -100 <= Node.val <= 100
- Both
list1
andlist2
are sorted in non-decreasing order.
Chinese (合并两个有序链表)
将两个升序链表合并为一个新的 升序 链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。
示例 1:
graph LR
node11((1))
node12((2))
node13((4))
node11 -----> node12 -----> node13
node21((1))
node22((3))
node23((4))
node21 -------> node22 -----> node23
node31((1))
node32((1))
node33((2))
node34((3))
node35((4))
node36((4))
node31 ---> node32 ---> node33 ---> node34 ---> node35 ---> node36
1 |
|
示例 2:
1 |
|
示例 3:
1 |
|
提示:
- 两个链表的节点数目范围是
[0, 50]
-100 <= Node.val <= 100
l1
和l2
均按 非递减顺序 排列
Solution
1 |
|
LeetCode 21 - Merge Two Sorted Lists
http://wasprime.github.io/Algorithm/LeetCode/LinkedList/LeetCode-21-Merge-Two-Sorted-Lists/