Easy solution using three pointer approach


#1

ListNode* Solution::swapPairs(ListNode* head) {
ListNode * prev = NULL;
ListNode* current = head;
ListNode* nextptr;

int k = 2, count = 0;
while(current!=NULL && count<k){
nextptr = current->next;
current->next = prev;
//current= current->next;
prev = current;
current= nextptr;
count++;
}
if(nextptr!=NULL){
head->next = swapPairs(nextptr);
}

return prev;

}

Comment body goes here.