You are given the heads of two singly linked lists sorted in non-decreasing order. Your task is to merge them into a single sorted linked list and return the head of the merged list.
Example 1
Input: list1 = [1,2,4], list2 = [1,3,4]
Output: [1,1,2,3,4,4]
Explanation: The two sorted linked lists are merged into a single sorted linked list.
Example 2
Input: list1 = [], list2 = [0]
Output: [0]
Explanation: Since the first linked list is empty, the merged list is the second linked list.
Example 3
Input: list1 = [2,5,7], list2 = [1,3,6,8]
Output: [1,2,3,5,6,7,8]
Explanation: The nodes from both linked lists are merged while maintaining sorted order.
Sign in to write, run, and submit your solution against the full test suite.