9ms and concise java solution


  • 0
    K

    if(head==null || head.next==null) return head;
    ListNode dummy=new ListNode(0);
    dummy.next=head;
    ListNode cur=head;
    ListNode position;
    while(cur.next!=null){
    ListNode temp=cur.next;
    if(temp.val<cur.val){
    cur.next=temp.next;
    position=dummy;
    while(temp.val>position.next.val)
    position=position.next;
    temp.next=position.next;
    position.next=temp;
    }
    else cur=cur.next;
    }
    return dummy.next;

    schwein~~~


Log in to reply
 

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