You are viewing a single comment's thread. Return to all comments →
See this one has O(1) complexity
bool has_cycle(Node* head) { if(head==NULL||head->next==NULL) return head; int index=0; Node* temp= head; while(temp && index<101){ index++; temp=temp->next; } if(index==101) return 1; return 0; }
Seems like cookies are disabled on this browser, please enable them to open this website
Cycle Detection
You are viewing a single comment's thread. Return to all comments →
See this one has O(1) complexity