/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) { val = x; }
 * }
 */
public class Solution {
    public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
        // the first three lines can speed up the algorithm
        if(l1 == null && l2 == null) return null;
        if(l1 == null) return l2;
        if(l2 == null) return l1;
        
        ListNode dummy = new ListNode(0);
        ListNode current = dummy;
        while(l1 != null && l2 != null) {
        	if(l1.val < l2.val) {
        		current.next = l1;
        		l1 = l1.next;
        	} else {
        		current.next = l2;
        		l2 = l2.next;
        	}
        	current = current.next;
        }
        if(l1 != null)      current.next = l1;
        else if(l2 != null) current.next = l2;
        return dummy.next;        
    }
}

@@ -882,8 +882,632 @@
     %7D%0A%7D%0A
+%0A// solution 2: recursive solution%0Apublic class Solution %7B%0A    public ListNode mergeTwoLists(ListNode l1, ListNode l2) %7B%0A        ListNode dummy = new ListNode(0);%0A        dummy.next = helper(l1, l2);%0A        return dummy.next;      %0A    %7D%0A    %0A    private ListNode helper(ListNode l1, ListNode l2) %7B%0A        if(l1 == null && l2 == null) return null;%0A        if(l1 == null) return l2;%0A        if(l2 == null) return l1;%0A        %0A        if(l1.val %3C l2.val) %7B%0A            l1.next = helper(l1.next, l2);%0A            return l1;%0A        %7D else %7B%0A            l2.next = helper(l1, l2.next);%0A            return l2;%0A        %7D%0A    %7D%0A%7D%0A

Update 021.java