"""
Definition of ListNode
class ListNode(object):
def __init__(self, val, next=None):
self.val = val
self.next = next
"""
class Solution:
"""
@param head: a ListNode
@return: a ListNode
"""
def swapPairs(self, head):
# write your code here
if head == None:
return
cur = ListNode(0)
cur.next = head
first = cur #first始终没变 指向head 故返回其next就是整个链表
#整个循环就是 temp的使用
while cur.next and cur.next.next:
cur1 = cur.next
cur2 = cur1.next
cur3 = cur2.next
cur1.next = cur3
cur2.next = cur1
cur.next = cur2
cur = cur1
return first.next