eolymp
bolt
Try our new interface for solving problems
Problems

LinkedList Merge

LinkedList Merge

Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.

Definition of a single linked list:

// Java
class ListNode {
  int val;
  ListNode next;
  ListNode(int x) {
    val = x;
    next = null;
  }
}
// C++
class ListNode
{
public:
  int val;
  ListNode *next;
  ListNode(int x) : val(x), next(NULL) {}
};

Implement function merge that merges two linked lists.

// Java
ListNode merge(ListNode l1, ListNode l2)
// C++
ListNode* merge(ListNode *l1, ListNode *l2)

Example

prb10044.gif

Time limit 1 second
Memory limit 128 MiB
Author Mykhailo Medvediev