乌龟和兔子
摘要:如何找到链表中的循环?弗洛伊德有一个算法,也叫兔子和乌龟算法,boolean hasLoop(Node first) { if(first == null) // list does not exist..so no loop either. return false; Node slow, fast; // create two references. slow = fast = first; // make both refer to the start of the list. while(true) { slow = slow.nex...
阅读全文
posted @
2013-09-07 18:59
maxc01
阅读(750)
推荐(0)