Given two sorted linked lists consisting of nodes respectively. The task is to merge both lists and return the head of the merged list.
Example 1
Input: LinkedList1: 10->20->30, LinkedList2: 5->15->25->35
Output: 5->10->15->20->25->30->35
Explanation: Nodes from both linked lists are merged step-by-step into a new sorted linked list.
Example 2
Input: LinkedList1: 5->6->7, LinkedList2: 5->6->7
Output: 5->5->6->6->7->7
Explanation: Duplicate elements are allowed and are added in the order of their occurrence.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
10 20 30 5 15 25 35
5 10 15 20 25 30 35
5 6 7 5 6 7
5 5 6 6 7 7