@@ -0,0 +1,1601 @@
+package leetcode.merge_two_sorted_lists;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Random;%0A%0Aimport common.ListNode;%0A%0Apublic class Solution %7B%0A%09public ListNode mergeTwoLists(ListNode l1, ListNode l2) %7B%0A%09%09if(l1 == null) return l2;%0A%09%09if(l2 == null) return l1;%0A%09%09ListNode cur1 = l1, cur2 = l2;%0A%09%09ListNode cur;%0A%09%09ListNode head;%0A%09%09if(cur1.val %3E cur2.val)%7B%0A%09%09%09head = cur2;%0A%09%09%09cur2 = cur2.next;%0A%09%09%7Delse%7B%0A%09%09%09head = cur1;%0A%09%09%09cur1 = cur1.next;%0A%09%09%7D%0A%09%09cur = head;%0A%09%09while(cur1 != null && cur2 != null)%7B%0A%09%09%09if(cur1.val %3E cur2.val)%7B%0A%09%09%09%09cur.next = cur2;%0A%09%09%09%09cur = cur2;%0A%09%09%09%09cur2 = cur2.next;%0A%09%09%09%7Delse%7B%0A%09%09%09%09cur.next = cur1;%0A%09%09%09%09cur = cur1;%0A%09%09%09%09cur1 = cur1.next;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09if(cur1 != null) cur.next = cur1;%0A%09%09if(cur2 != null) cur.next = cur2;%0A%09%09return head;%0A%09%7D%0A%0A%09public static void dump(ListNode head)%7B%0A%09%09ListNode cur = head;%0A%09%09while(cur != null)%7B%0A%09%09%09System.err.print(cur.val + %22, %22);%0A%09%09%09cur = cur.next;%0A%09%09%7D%0A%09%09System.err.println(%22%22);%0A%09%7D%0A%09%0A%09public static void main(String%5B%5D args)%7B%0A%09%09final int N = 1;%0A%09%09Random r = new Random();%0A%09%09ArrayList%3CListNode%3E ary1 = new ArrayList%3CListNode%3E();%0A%09%09for(int i = 0; i %3C N; i++)%7B%0A%09%09%09int v = 0;%0A%09%09%09if(i %3E 0) v = ary1.get(i - 1).val; %0A%09%09%09ary1.add(new ListNode(v + r.nextInt(2)));%0A%09%09%09if(i %3E 0) ary1.get(i - 1).next = ary1.get(i);%0A%09%09%7D%0A%09%09%0A%09%09ArrayList%3CListNode%3E ary2 = new ArrayList%3CListNode%3E();%0A%09%09for(int i = 0; i %3C N; i++)%7B%0A%09%09%09int v = 0;%0A%09%09%09if(i %3E 0) v = ary2.get(i - 1).val; %0A%09%09%09ary2.add(new ListNode(v + r.nextInt(2)));%0A%09%09%09if(i %3E 0) ary2.get(i - 1).next = ary2.get(i);%0A%09%09%7D%0A%09%09dump(ary1.get(0));%0A%09%09dump(ary2.get(0));%0A%09%09dump(new Solution().mergeTwoLists(ary1.get(0), ary2.get(0)));%0A%09%7D%0A%7D%0A

Add java solution for 21. Merge Two Sorted Lists