标签:tno == sha log csharp head arp sort pre
class Solution { public ListNode sortList(ListNode head) { if(head==null||head.next==null) return head; ListNode p=head,q=head; while(p.next!=null&&p.next.next!=null) { q=q.next; p=p.next.next; } ListNode l2=sortList(q.next); q.next=null; ListNode l1=sortList(head); return merge(l1,l2); } private ListNode merge(ListNode l1, ListNode l2){ ListNode l=new ListNode(0); ListNode p=l; while(l1!=null||l2!=null) { if(l1!=null&l2!=null&&l1.val<l2.val||l2==null) { p.next=l1; l1=l1.next; } else { p.next=l2; l2=l2.next; } p=p.next; } return l.next; } }
标签:tno == sha log csharp head arp sort pre
原文地址:http://www.cnblogs.com/asuran/p/7679752.html