1. 程式人生 > >Merge Two Sorted Lists (LL)

Merge Two Sorted Lists (LL)

lis style head listnode get sort urn nbsp sts

 1 //10 ms
 2 class Solution {
 3     public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
 4         if(l1 == null) return l2;
 5         if(l2 == null) return l1;
 6         ListNode head = null;
 7         
 8         if(l1.val < l2.val) {
 9             head = l1;
10             head.next = mergeTwoLists(l1.next, l2);
11 }else { 12 head = l2; 13 head.next = mergeTwoLists(l1, l2.next); 14 } 15 return head; 16 } 17 }

Merge Two Sorted Lists (LL)