/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
class Solution {
public ListNode swapPairs(ListNode head) {
if(head==null||head.next==null)
return head;
ListNode p=head;
ListNode root=head.next;
ListNode q=head.next;
ListNode pre=null;
while(q!=null&&p!=null)
{
ListNode nex=q.next;
q.next=p;
p.next=nex;
if(pre!=null)
pre.next=q;
pre=p;
p=p.next;
if(p!=null)
q=p.next;
}
return root;
}
}