Leetcode 21. Merge Two Sorted Lists
You are given the heads of two sorted linked lists list1 and list2.
Merge the two lists into one sorted linked list and return the head of the new sorted linked list.
The new list should be made up of nodes from list1 and list2.
Examples
Example 1
Input: list1 = [], list2 = [1,2]
Output: [1,2]
Example 2
Input: list1 = [], list2 = []
Output: []
Constraints
0 <= The length of the each list <= 100-100 <= Node.val <= 100
How the tests work: lists are written as arrays —
[1,2,3]is the chain1 → 2 → 3. Your function receives realListNodeobjects, and the list you return is read back into an array.