题目:
题解:
class Solution:def swapPairs(self, head: ListNode) -> ListNode:dummyHead = ListNode(0)dummyHead.next = headtemp = dummyHeadwhile temp.next and temp.next.next:node1 = temp.nextnode2 = temp.next.nexttemp.next = node2node1.next = node2.nextnode2.next = node1temp = node1return dummyHead.next