f**h 发帖数: 1149 | 1 有可能很多人都听过的
What is the procedure to be applied for finding whether there is any circle
formed in a linked list? Assume the linked list is very long |
w****l 发帖数: 88 | 2 用两个指针,开始是同时指向链表的头结点,然后一个指针每次向前两步,另一个指针
每次向前一步,如果某个时刻两个指针指向同一个节点,说明有环....我是菜鸟,请大
侠指教.... |
f**h 发帖数: 1149 | 3 嘿嘿,我没听说过,反正没答出来,你是自己想出来的吗? |
s*********t 发帖数: 1663 | 4 careercup,chapter linkedlist
circle
【在 f**h 的大作中提到】 : 有可能很多人都听过的 : What is the procedure to be applied for finding whether there is any circle : formed in a linked list? Assume the linked list is very long
|
J******e 发帖数: 225 | 5 很经典的题目,算法也很简单很好记,龟兔算法
http://en.wikipedia.org/wiki/Tortoise_and_hare_algorithm#Tortoise_and_hare
还有变化是找到Circle的长度
circle
【在 f**h 的大作中提到】 : 有可能很多人都听过的 : What is the procedure to be applied for finding whether there is any circle : formed in a linked list? Assume the linked list is very long
|
w****l 发帖数: 88 | |