0021. Merge Two Sorted Lists
Easy | Linked List + Recursion | 16ms (98.84%), 13.4 MB (87.61%)
Source: LeetCode - Merge Two Sorted Lists GitHub: Solution / Performance
Merge two sorted linked lists and return them as a sorted list. The list should be made by "splicing" together (with) the nodes of the first two lists.
According to the problem statement, we cannot create a new linked list to store sorted nodes.
Therefore, top-down recursion could help us sort by in-place modification on either l1 or l2 as a starting node.
Last updated