My Python AC Code with 40ms.

  • 0
    class Solution(object):
        def swapPairs(self, head):
            :type head: ListNode
            :rtype: ListNode
            p = head
            if p is None or is None:
                return p
            q =
            head = q
            pre = ListNode(-1)
            while p and q:
                t =
       = p
       = t
       = q
                pre = p
                if t and
                    p = t
                    q =
            return head

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.