输出:结点C
可以用一个map<node*,bool> 就解决问题了。
下面是编程之美上一种奇特的解法:快慢指针解法。
代码:
struct SNode { int data; SNode* next; }; SNode* findCirleStart(const SNode* vHead) { if (vHead->next == NULL) return NULL; SNode* Fast = vHead; SNode* Slow = vHead; while (Slow && Fast->next) { Slow = Slow->next; Fast = Fast->next->next; if (Slow == Fast) break; } Slow = vHead; while (Slow != Fast) { Slow = Slow->next; Fast = Fast->next; } return Fast; }
010给定一个循环链表,实现一个算法返回这个环的开始结点 (keep it up)
原文地址:http://blog.csdn.net/xiaoliangsky/article/details/38760983