力扣 24 交换链表节点
class Solution:
def swapPairs(self, head: Optional[ListNode]) -> Optional[ListNode]:
dummy_head = ListNode(next = head)
cur = dummy_head
while cur.next and cur.next.next:
temp = cur.next.next.next
cur.next.next.next = cur.next
cur.next = cur.next.next
cur.next.next.next = temp
cur = cur.next.next
return dummy_head.next