Java-合并链表(递归)
合并两个排序的链表
http://www.nowcoder.com/questionTerminal/d8b6b4358f774294a89de2a6ac4d9337
合并链表,递归比较链表的头,哪个小就next哪个
/* public class ListNode { int val; ListNode next = null; ListNode(int val) { this.val = val; } }*/ public class Solution { public ListNode Merge(ListNode list1,ListNode list2) { if(list1==null) return list2; if(list2==null) return list1; ListNode Merge_=null; if(list1.val<list2.val){ Merge_=list1; Merge_.next=Merge(list1.next,list2); }else{ Merge_=list2; Merge_.next=Merge(list1,list2.next); } return Merge_; } }