AcWing 34. 链表中环的入口结点-Java
原题链接
中等
作者:
小土豆_jxy
,
2021-03-24 23:30:16
,
所有人可见
,
阅读 306
class Solution {
public ListNode entryNodeOfLoop(ListNode head) {
if(head == null || head.next == null){
return null;
}
ListNode quick = head.next.next,slow = head.next;
boolean isCircle = false;
while(quick != null && quick.next != null){
if(quick != slow){
quick = quick.next.next;
slow = slow.next;
}else{
slow = head;
while(slow != quick){
slow = slow.next;
quick = quick.next;
}
return slow;
}
}
return null;
}
}