Nonetype has no attribute for .next

  • 0

    Hi I have a very weird question here.
    I had my answer right as following:

    def hasCycle(self, head): 
        slow = head
        fast = head
        while (( != None) and (fast != None)):
            slow =
            fast =
            if (fast ==slow):
                return True
        return False

    but once I tried to switch the order of != None

    and != None

    It shows Nonetype has no attribute for .next

    Does anyone knows why?

  • 0

    if head is None,when program run to the while,first i would check whether the fast have the next attribute,but the head is None,so the program directly throw the error do not run the next !

Log in to reply

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