Combine two sorted linked lists into one sorted list and return its head.
You get the heads of two singly linked lists, a and b. Each list is sorted in ascending order (smallest first). The result must also be in ascending order.
- Build the result by reusing the existing nodes. Relink their
nextreferences. Don't create new nodes. - Either list can be
null(empty). If both arenull, returnnull. - Values can repeat, inside one list and across both lists. Values can be negative.
Input: a = 1 → 4 → 6, b = 2 → 3 → 7
Output: 1 → 2 → 3 → 4 → 6 → 7
Input: a = null, b = 0 → 5
Output: 0 → 5