HELP(time limited exceed)


  • -1
    H
    void reorderList(ListNode *head) {
        // IMPORTANT: Please reset any member data you declared, as
        // the same Solution instance will be reused for each test case.
        
        
        ListNode* node = head;
        ListNode* front;
        ListNode* back;
        while(node != NULL)
        {
            front = node->next;
            if(front == NULL)
            return;
            
            back = front->next;
            if(back == NULL)
            return;
            
            while(back->next!= NULL)
            {   
                front = front->next;
                back = back->next;
            }
            
            back->next = node->next;
            node->next = back;
            front->next= NULL;
        
            node= node->next->next;
        }
        
    
        
    }

  • 0
    S

    Please tell your algorithm in some words and add some comments in your code, it will make others help you easily.


  • 0

    You need to show that you have done minimal research before asking a question. Please read the FAQ for guidelines on how to ask a question.


Log in to reply
 

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