How can this code not work for (206) Reverse Linked List ?


  • -1
    P
    class Solution(object):
    def reverseList(self, head):
        if head is None or head.next is None:
             return
        pre = head
        head = head.next
        while head is not None:
            temp = head.next
            head.next = pre
            pre = head
            head = temp
        return pre
    

    how could this take too much time ?please help me ,i cannot finger out any way ....


Log in to reply
 

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