Simple Python solution

  • 0

    Recursive where each call swaps a pair of nodes and recursively make another call to swap the rest of the list

    class Solution(object):
        def swapPairs(self, head):
            :type head: ListNode
            :rtype: ListNode
            if head is None or is None:
                return head
            n = self.swapPairs(
            second =
   = head
   = n
            return second

Log in to reply

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