My Python Solution


  • -1
    B
    class Solution(object):
        def swapPairs(self, head):
            if head:
                if head.next:
                    temp = head.next
                    later = self.swapPairs(temp.next)
                    temp.next = head
                    head.next = later
                    return temp
                else:
                    head.next = None
                    return head
            else:
                return None

Log in to reply
 

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