Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def swapPairs(self, head):
- """
- :type head: ListNode
- :rtype: ListNode
- """
- res = ListNode(0)
- res.next = head
- pre = res
- while pre.next and pre.next.next:
- temp = pre.next.next # 先保存后一段的链表
- pre.next.next = temp.next #
- temp.next = pre.next # swap process
- pre.next = temp #
- pre = temp.next
- return res.next
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement