Why is this code a wrong version???


  • 0

    class Solution {
    public:
    bool hasCycle(ListNode head) {
    if(head == NULL) return false;
    ListNode
    fast = head, *slow = head;
    while(fast != NULL && slow != NULL)
    {
    fast = fast -> next -> next;
    slow = slow -> next;
    if(fast == slow)
    return true;
    }
    return false;
    }
    };


Log in to reply
 

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