C++ solution sharing (9ms)


  • 0
    N
    class Solution {
    public:
        bool hasCycle(ListNode *head) {
            if(head==NULL)return false;
            head->val=98765432;
            while(head->next)
            {
                head=head->next;
                if(head->val==98765432)return true;
                head->val=98765432;
            }
            return false;
        }
    };

Log in to reply
 

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