You get list1 and list2, the first nodes of two singly linked lists. Every list node holds an integer val and a pointer next to the node after it; the last node's next is empty. Each list is sorted in ascending order, and values can repeat, inside one list and across both. Return the head of a single list that holds every value of both lists, also in ascending order. Equal values all stay: a value that appears twice in total appears twice in the result.
Either list can be empty, which means it has no nodes at all. If one list is empty, the result is the other list; if both are empty, return an empty list. You may relink the nodes you were given or build new ones; only the values in the result, from head to tail, are checked.
In the examples and test cases a list is written as an array of its values from head to tail, so [2, 5, 11] is the node 2 pointing at 5 pointing at 11.