class(object): defswapPairs(self, head): """ :type head: ListNode :rtype: ListNode """ res = ListNode(0) res.next = head cur = res while cur.next and cur.next.next: a = cur.next b = cur.next.next cur.next, b.next, a.next = b, a, b.next # cur.next = b # b.next = a # a.next = c cur = a return res.next
近期评论