Why my code Runtime Error at case {1, 1}


  • 0
    T
    ListNode *insertionSortList(ListNode *head) {
            ListNode **cur = &head;
            
            while(*cur)
            {
                ListNode *temp = (*cur)->next;
                for(ListNode **run = &head; *run != *cur; run = &(*run)->next)
                {
                    if((*cur)->val <= (*run)->val)
                    {
                        *cur = (*cur)->next;
                        (*cur)->next = *run;
                        *run = *cur;
                        break;
                    }
                }
                cur = &temp;
            }
            
            return head;
        }
    

    A concise solution.


Log in to reply
 

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