You are viewing a single comment's thread. Return to all comments →
// A C++ solution with set
#include <set> bool has_cycle(Node* head) { set<Node *> det; if (head == NULL) return false; while (head != NULL) { if (det.find(head) != det.end()) return true; det.insert(head); head = head->next; } return false; }
Linked Lists: Detect a Cycle
You are viewing a single comment's thread. Return to all comments →
// A C++ solution with set