Solution using recursion


  • 0
    M

    class Solution {

    public:

    ListNode* start = NULL;
    bool flag = true;
    void reorderList(ListNode* head) {
        if(head!=NULL){
            if(start==NULL)
                start = head;
            reorderList(head->next);
            if(flag){
                if(start==head || start->next==head){
                    head->next = NULL;
                    flag = false;
                }else{
                    ListNode* tmp = start->next;
                    start->next = head;
                    head->next = tmp;
                    start = tmp;
                }
            }
        }
    }
    

    };


Log in to reply
 

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