715. Merge Two Sorted Linked Lists
0
Medium
You are given the heads of two sorted linked lists l1 and l2.
Merge the two lists in a one sorted list. The list should be made by splicing together the nodes of the first two lists.
Your task is to print the merged linked list.
Merge the two lists in a one sorted list. The list should be made by splicing together the nodes of the first two lists.
Your task is to print the merged linked list.
Input Format
First line contains two space separated integers specifying the size of both the list.
Second line contains the elements of first list.
Third line contains the elements of second list.
Second line contains the elements of first list.
Third line contains the elements of second list.
Output Format
Print the merged linked list.
*If there is no element in the merged linked list then print -1*
*If there is no element in the merged linked list then print -1*
Example
Input
3 5
3 5 9
1 3 4 8 9
Output
1 3 3 4 5 8 9 9
Constraints
The number of nodes in both lists is in the range [0, 100].
-100 <= Node.val <= 100
Both list1 and list2 are sorted in non-decreasing order.
-100 <= Node.val <= 100
Both list1 and list2 are sorted in non-decreasing order.
Loading...
View Submissions
Console