Skip to content

Instantly share code, notes, and snippets.

@ceth-x86
Created January 8, 2021 05:00
Show Gist options
  • Save ceth-x86/4e39891ea2054b1b7f3fafd449d6013b to your computer and use it in GitHub Desktop.
Save ceth-x86/4e39891ea2054b1b7f3fafd449d6013b to your computer and use it in GitHub Desktop.
class Solution {
public:
ListNode* swapPairs(ListNode* head) {
ListNode **pp = &head, *a, *b;
while ((a = *pp) && (b = a->next)) {
a->next = b->next;
b->next = a;
*pp = b;
pp = &(a->next);
}
return head;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment