AcWing 34. 链表中环的入口结点-Java
原题链接
中等
作者:
Fant.J
,
2019-05-14 10:37:49
,
所有人可见
,
阅读 1250
class Solution {
public ListNode entryNodeOfLoop(ListNode head) {
if(head == null){return null;}
ListNode fast = head;
ListNode slow = head;
while(fast.next.next != null && slow.next != null){
fast = fast.next.next;
slow = slow.next;
if(fast.val == slow.val){
slow = head;
while(fast.next != null && slow.next != null){
fast = fast.next;
slow = slow.next;
if(fast.val == slow.val){
return slow;
}
}
}
}
return null;
}
}