Accode:
public class Solution {
public ListNode detectCycle(ListNode head) {
ListNode slow = head, fast = head;
while (true) {
if (fast == null || fast.next == null) return null;
slow = slow.next;
fast = fast.next.next;
if (slow == fast) break;
}
fast = head;
while (slow!=fast) {
slow = slow.next;
fast = fast.next;
}
return slow;
}
}
over~
标签:II,head,slow,142,fast,next,链表,ListNode,null From: https://blog.csdn.net/m0_74969835/article/details/137054655