My solution suffer TEL why?


  • 0
    W
    public class Solution {
        public ListNode insertionSortList(ListNode head) {
            if(head==null||head.next==null) return head;
            ListNode beforehead=new ListNode(0);
            beforehead.next=head;
             return SortList(beforehead,head.next);
    
            }
            public ListNode SortList(ListNode first,ListNode next){
                if(first.next==null||first.next.next==null) return first.next;
                ListNode h1=SortList(first.next,next.next);
                ListNode temp=first.next;
                ListNode beforeh1=h1;
                next=next.next;
                while(h1!=null&&temp.val>h1.val){
                    first.next=h1;
                    beforeh1=h1;
                    h1=h1.next;
                    
                }
                beforeh1.next=temp;
                temp.next=h1;
                return first.next;
                
            }
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.