```
class Solution(object):
def swapPairs(self, head):
"""
:type head: ListNode
:rtype: ListNode
"""
p = head
if p is None or p.next is None:
return p
q = p.next
head = q
pre = ListNode(-1)
while p and q:
t = q.next
q.next = p
p.next = t
pre.next = q
pre = p
if t and t.next:
p = t
q = t.next
else:
break
return head
```