You are viewing a single comment's thread. Return to all comments →
Clean C++ solution:
Node* next(Node* node) { if (node) node = node->next; return node; } bool has_cycle(Node* head) { Node* slow = next(head); Node* fast = next(next(head)); while (slow != fast) { slow = next(slow); fast = next(next(fast)); } return fast; }
Seems like cookies are disabled on this browser, please enable them to open this website
Linked Lists: Detect a Cycle
You are viewing a single comment's thread. Return to all comments →
Clean C++ solution: