class Solution {
public:
/**
* @param ListNode l1 is the head of the linked list
* @param ListNode l2 is the head of the linked list
* @return: ListNode head of linked list
*/
ListNode *mergeTwoLists(ListNode *l1, ListNode *l2) {
// write your code here
ListNode* l3 = new ListNode(0);
ListNode* l4=l3;
ListNode* l5=l4;
while ( l1 != NULL&&l2 != NULL ){
if ( l1->val < l2->val ){
l3->next = l1;
l1 = l1->next;
l3 = l3->next;
}
else {
l3->next = l2;
l2 = l2->next;
l3 = l3->next;
}
}
if ( l1 == NULL ){
l3->next = l2;
}else
l3->next = l1;
delete l5;
return l4->next;
}
};