LC24. 两两交换链表中的节点
class Solution(object):
def swapPairs(self, head):
"""
:type head: ListNode
:rtype: ListNode
"""
dummy = ListNode(0)
first = head
dummy.next = first
if not first:
return first
elif not first.next:
print(first)
return first
newHead = first.next
while first and first.next:
temp = first.next.next
first.next.next = first
dummy.next = first.next
dummy = first
first.next = temp
first = temp
return newHead