剑指 Offer II 022. 链表中环的入口节点
其实本题的难点在于如果数学推导。
public class Solution {public ListNode detectCycle(ListNode head) {// 入口节点if (head == null) return null;ListNode fast = head, slow = head;while (fast != null && fast.next != null) {fast = fast.next.next;slow = slow.next;// 环中相遇if (fast == slow) {fast = head;while (fast != slow) {fast = fast.next;slow = slow.next;}return fast;}}return null;}}
