LinkedList Merge#10044

LinkedList Merge

1 second
128 megabytes
Easy

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:

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

Implement function merge that merges two linked lists.

ListNode merge(ListNode l1, ListNode l2)
ListNode* merge(ListNode *l1, ListNode *l2)

Example

prb10044.gif