You are viewing a single comment's thread. Return to all comments →
No, it will work. Please refer....!
bool has_cycle(SinglyLinkedListNode* head) { SinglyLinkedListNode* temp = head; while (true) { if(temp->next < temp) return (temp->next == nullptr) ? false : true; temp = temp->next; } }
My submission: https://www.hackerrank.com/challenges/detect-whether-a-linked-list-contains-a-cycle/submissions/code/104878239
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 →
No, it will work. Please refer....!
bool has_cycle(SinglyLinkedListNode* head) { SinglyLinkedListNode* temp = head; while (true) { if(temp->next < temp) return (temp->next == nullptr) ? false : true; temp = temp->next; } }
My submission: https://www.hackerrank.com/challenges/detect-whether-a-linked-list-contains-a-cycle/submissions/code/104878239