VV Easy to understand C++ soln


#1
ListNode* Solution::swapPairs(ListNode* A) {
    ListNode *temp = new ListNode(0);
    temp->next = A;
    ListNode *curr = temp;
    while(curr->next != NULL && curr->next->next != NULL){
        ListNode *first = curr->next;
        ListNode *second = curr->next->next;
        
        first->next = second->next;
        curr->next = second;
        curr->next->next = first;
        curr = curr->next->next;
    }
    return temp->next;
}

Just dry run it on paper, and you will get it.