=》 https://www.acwing.com/problem/content/86/
=》题解 https://www.acwing.com/solution/content/741/
class Solution {
public:
ListNode *entryNodeOfLoop(ListNode *head) {
auto i = head, j = head;
while(i != nullptr && j != nullptr)
{
i = i->next;
j = j->next;
if(j)
{
j = j->next;
if(j == nullptr) return nullptr;
}
if(i == j && i && j) //保证i和j不相等
{
i = head;
while(i != j)
{
i = i->next;
j = j->next;
}
return i;
}
}
return nullptr;
}
};