Skip to content

Instantly share code, notes, and snippets.

@zhangxiaomu01
Created November 17, 2018 02:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhangxiaomu01/505e2e8d3becf64972bc99d374046e1b to your computer and use it in GitHub Desktop.
Save zhangxiaomu01/505e2e8d3becf64972bc99d374046e1b to your computer and use it in GitHub Desktop.
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* swapPairs(ListNode* head) {
if(head == NULL || head->next == NULL){
return head;
}
ListNode *p = head->next;
head->next = swapPairs(head->next->next);
p->next = head;
return p;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment