leecode24 发表于 2019-06-03 | 分类于 leecode | 字数统计 69 | 阅读时长 1 1234567891011121314151617181920212223242526272829class Solution: def swapPairs(self, head: ListNode) -> ListNode: newhead = ListNode(0) newhead.next = head l1 = newhead if l1.next is None: return head l2 = newhead.next.next if l2 is None: return head while True: tmp = l1.next l1.next = l2 tmp.next = l2.next l2.next = tmp l1 = tmp if l1.next is None: break l2 = l1.next.next try: l2.next except: break return newhead.next