class Solution {
public:
ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) {
if (l1==NULL) return l2;
if (l2==NULL) return l1;
ListNode* temp;
// Assume l1 < l2
if (l1->val > l2->val){
temp = l2;
l2 = l1;
l1 = temp;
}
ListNode* head = l1;
while(l2!=NULL){
while(l1->next!=NULL && ((l1->next)->val<= (l2->val))) l1 = l1->next;
temp = l1->next;
l1->next = l2;
l1 = l2;
l2 = temp;
}
return head;
}
};