My C++ Solution


  • 0
    T
    class Solution {
    public:
        bool hasCycle(ListNode *head) {
            
            ListNode* snow = head;
            ListNode* quick = head;
            
            while(quick != NULL && quick->next != NULL)
            {
                snow = snow->next;
                quick = quick->next->next;
                if(snow == quick)
                    return true;
            }
            return false;
        }
    };
    

Log in to reply
 

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