9 lines C accepted in 6ms without extra space


  • 0
    J

    bool hasCycle(struct ListNode *head) {
    if(!head) return false;
    while(head->next){
    head->val = (int)head;
    if((struct ListNode *)head->next->val == head->next) return true;
    head = head->next;
    }
    return false;
    }


Log in to reply
 

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