/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode() : val(0), next(nullptr) {}
* ListNode(int x) : val(x), next(nullptr) {}
* ListNode(int x, ListNode *next) : val(x), next(next) {}
* };
*/
class Solution {
public:
ListNode* swapPairs(ListNode* head) {
ListNode *L=new ListNode(0);
ListNode* p=L;
L->next=head;
while( p->next && p->next->next){
ListNode* node1=p->next;
ListNode* node2=p->next->next;
p->next=node2;
node1->next=node2->next;
node2->next=node1;
p=node1;
}
return L->next;
}
};