My 12ms C++ solution


  • 0
    D

    class Solution {
    public:
    bool hasCycle(ListNode *head) {
    ListNode *cur=head;
    while(cur){
    if(cur->next==cur)return true;
    ListNode *tmp=cur->next;
    cur>next=cur; //make the visited node point to itself
    cur=tmp;
    }
    return false;
    }
    };


Log in to reply
 

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