题目描述
blablabla
样例
blablabla
算法1
blablabla
时间复杂度分析:blablabla
C++ 代码
class Solution {
public ListNode entryNodeOfLoop(ListNode head) {
if(head == null){return null;}
if (isCycle(head)==null)
return null;
ListNode node=isCycle(head);
ListNode first=head;
while (first!=node){
first=first.next;
node=node.next;
}
return first;
}
public ListNode isCycle(ListNode node){
ListNode fast=node;
ListNode slow=node;
while(fast.next.next != null && slow.next != null){
fast=fast.next.next;
slow=slow.next;
if (fast==slow)
return fast;
}
return null;
}
}