Easy understand solution


  • 0
    M

    class Solution {
    public:
    ListNode* swapPairs(ListNode* head) {
    if(head==NULL || head->next==NULL){
    return head;
    }
    else
    {
    ListNode * post = head->next;
    ListNode* after=post->next;
    post->next=head;
    head->next = swapPairs(after);
    return post;
    }

    }
    

    };


Log in to reply
 

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