C++ 9ms recursion(Is that a cheating solution)?


  • 0
     bool hasCycle(ListNode *head) {
            if(head==NULL) return false;
            if(head->val==-1&&head->next->val==-1) return true;
            head->val=-1;
            return hasCycle(head->next);
        }
    

Log in to reply
 

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