Your question is Combine Two Sorted Lists. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
PlayStation Network services may maintain sorted linked lists of records, such as queued content identifiers or ordered activity entries. Given two linked lists whose values are sorted in non-decreasing order, merge them into one sorted linked list.
Reuse the existing nodes rather than creating a new node for every value. Return the head of the merged list. The input lists may be empty.
Implement merge_two_lists(list1, list2).
list1 and list2 are either None or references to the heads of singly linked lists.val field and a next field containing another node or None.[1, 4] represents 1 -> 4 -> None.def merge_two_lists(list1, list2):