Merge Two Sorted Lists
LINKED LIST
RECURSION
Problem
Given the heads of two sorted linked lists list1
and list2
, merge the two lists into one sorted linked list. The new list should be made by splicing together the nodes of the first two lists. Return the head of the merged linked list.
Examples
mergeTwoLists([5, 10, 20, 30], [2, 8, 25, 35]) // [2, 5, 8, 10, 20, 25, 30, 35] mergeTwoLists([100], [50, 75]) // [50, 75, 100] mergeTwoLists([], [10, 20, 30, 40]) // [10, 20, 30, 40]
Loading...
5
10
20
30
2
8
25
35