Why my python solution is wrong


  • 0
    C
    # Definition for singly-linked list.
    # class ListNode:
    #     def __init__(self, x):
    #         self.val = x
    #         self.next = None
    
    class Solution:
        # @param a ListNode
        # @return a ListNode
        def swapPairs(self, head):
        	if head == None or head.next == None:
        		return(head)
    		result = ListNode(0)
    		result.next, head = head, result
    		while result.next.next:
    			tmp = result.next.next
    			result.next.next = tmp.next
    			tmp.next = result.next
    			result.next = tmp
    		return(head.next)

Log in to reply
 

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