You are viewing a single comment's thread. Return to all comments →
bool has_cycle(Node* head) { if(head == NULL) { return false ; } struct Node* temp1 = head; while(temp1!=NULL) { struct Node* temp2 = temp1->next; while(temp2!=NULL) { if(temp1==temp2) return true; temp2 = temp2->next; } temp1 = temp1->next; } return false; }
since the max size can be 100 , I'm checking if the same pointer appears twice during traversal. its giving TLE . Can someone find out the error?
Linked Lists: Detect a Cycle
You are viewing a single comment's thread. Return to all comments →
since the max size can be 100 , I'm checking if the same pointer appears twice during traversal. its giving TLE . Can someone find out the error?