Splice two sorted lists
Write merge_sorted(a, b): a and b are the first nodes of two singly linked lists, each sorted from smallest to largest (repeats allowed; either may be None). Splice them into one sorted list and return its first node. Each ListNode has val and next.
Re-link the nodes you were given instead of creating new ones: O(1) extra memory.
The tests call the provided run_merge_sorted(a_values, b_values), which builds both lists from a_values and b_values and returns the values of the list you return.
Examples
run_merge_sorted([1,3,5], [2,4,6])→[1,2,3,4,5,6]run_merge_sorted([1,2,4], [1,3,4])→[1,1,2,3,4,4]run_merge_sorted([], [0])→[0]