My python solution--only swap values


  • -6
    X
    class Solution(object):
        def swapPairs(self, head):
            """
            :type head: ListNode
            :rtype: ListNode
            """
            if not head or not head.next:return head
            p = head
            while p and p.next:
                p.val, p.next.val = p.next.val, p.val
                p = p.next.next
            return head

Log in to reply
 

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