Simple Python Solution


  • 1
    Y
    def swapPairs(self, head):
    
            dummy = ListNode(-1)
            dummy.next = head
            current = dummy
            
            while current.next != None and current.next.next != None:
                first = current.next
                second = current.next.next
                
                current.next = second
                first.next = second.next
                second.next = first
          
                current = current.next.next
            return dummy.next

Log in to reply
 

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