# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
# @param {ListNode} head
# @return {ListNode}
def swapPairs(self, head):
if head == None or head.next == None:
return head
result = ListNode(0); result.next = head
p = result
while p.next and p.next.next:
temp = p.next.next
p.next.next = temp.next
temp.next = p.next
p.next = temp
p = p.next.next
return result.next