Merge Two Sorted Lists (LL)

 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 }

猜你喜欢

转载自www.cnblogs.com/goPanama/p/9495991.html