You are given the heads of two linked lists, l1 and l2.
Your task is to merge these two lists into one sorted list.
You may assume that:
l1 and l2, are already sorted in non-decreasing order.Return the head node of the new merged list.
l1 = 1 → 3 → 5 → null
l2 = 2 → 4 → 6 → 7 → 8 → null
1 → 2 → 3 → 4 → 5 → 6 → 7 → 8 → null
The two lists are merged in sorted order.
l1 = 1 → 2 → 4 → null
l2 = 1 → 3 → 4 → null
1 → 1 → 2 → 3 → 4 → 4 → null
The two lists are merged in sorted order, including duplicates.
l1 = None
l2 = None
None
Merging two empty lists results in an empty list.
l1 = None
l2 = 0 → 3 → 5 → null
0 → 3 → 5 → null
Merging an empty list with a non-empty list results in the non-empty list.
l1 = 2 → 6 → 8 → null
l2 = 1 → 3 → 7 → 9 → null
1 → 2 → 3 → 6 → 7 → 8 → 9 → null
Nodes are merged in order to maintain sorting.
l1 = 1 → 3 → 5 → null
l2 = 2 → 4 → 6 → 7 → 8 → null
1 → 2 → 3 → 4 → 5 → 6 → 7 → 8 → null