Linked ListMerge
Two linked lists are sorted in non-decreasing order. Merge them into one sorted list by splicing their nodes together, and print the merged values. The values are given as an array; build the linked list from them yourself, then solve it with pointers.
Input
Line 1: n and m, the lengths of the two lists. Line 2: the n values of the first list. Line 3: the m values of the second list.
Output
Print the merged list's values on one line.
Constraints
1 <= n, m <= 5000 -10^4 <= value <= 10^4
Example 1
Input
3 3 1 2 4 1 3 4
Output
1 1 2 3 4 4
Interleaving by value gives 1 1 2 3 4 4.