(AC) Recursion solution in C


  • 0
    1

    struct ListNode* swapPairs(struct ListNode* head) {
    if(!head)return NULL;
    if(!head->next)
    return head;
    struct ListNode* front=NULL,*behind=NULL,*tmp=NULL;
    front=head;
    behind=head->next;
    if(behind->next)
    tmp=behind->next;
    head=behind;
    head->next=front;
    head->next->next=NULL;
    if(tmp){
    head->next->next=swapPairs(tmp);
    }
    return head;
    }


Log in to reply
 

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