← 返回 amazon 的题目列表Merge Two Sorted Linked Lists
类型:online_judge
Given two sorted (non-decreasing) singly linked lists l1 and l2, merge them into one sorted list and return the head.
Requirements:
Reuse existing nodes (do not allocate a new node per input element; a single dummy node is allowed).
Time: O(n+m), Extra space: O(1) (excluding the output list).
Example:
Input: l1 = [1,2,4], l2 = [1,3,4]
Output: [1,1,2,3,4,4]
Constraints:
0 <= n, m <= 1e5
Node values in [-1e9, 1e9]
Example
Input
l1=[1,2,4]
l2=[1,3,4]
Output
[1,1,2,3,4,4]