Same code with different result


  • 0
    R
    def reverseList(self, head):
        r = None
        while head:
           head, head.next, r = head.next, r, head
    

    Here is my result:

    Runtime Error Message: Line 17: AttributeError: 'NoneType' object has no attribute 'next'

    Last executed input: [1]


  • 0
    L

    differnt code!Becaue in your code, head=head.next, r=head. As a result r=head.next.You should change the order.


Log in to reply
 

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