最近开始用Python解题
未学过正规的Python 因此对于一些观念尚不太了解
题目是将链表中的元素两两对调
例如: Given 1->2->3->4, return the list as 2->1->4->3
我的Code如下:
class Solution(object):
def swapPairs(self, head):
if head is None or head.next is None:
return head
dummy = ListNode(0)
dummy.next = head
pre = dummy
tmp = head
while tmp and tmp.next:
pre.next = tmp.next
tmp.next = tmp.next.next <