# Definition for singly-linked list.
class ListNode(object):
def __init__(self, x):
self.val = x
self.next = None
class Solution(object):
def swapPairs(self, head):
"""
:type head: ListNode
:rtype: ListNode
"""
dummyHead = ListNode(0)
dummyHead.next = head
p = dummyHead
while p.next and p.next.next:
node1 = p.next
node2 = node1.next
next = node2.next
p.next = node2
node2.next = node1
node1.next = next
p = node1
return dummyHead.next