Linked List Cycle II

/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     public int val;
 *     public ListNode next;
 *     public ListNode(int x) {
 *         val = x;
 *         next = null;
 *     }
 * }
 */
public class Solution {
    public ListNode DetectCycle(ListNode head) {
        if(head==null||head.next==null||head.next.next==null)
            return null;
        ListNode slow=head.next;
        ListNode fast=head.next.next;
        while(slow!=fast&&fast!=null&&fast.next!=null){
            slow=slow.next;
            fast=fast.next.next;
        }
        if(fast==null||fast.next==null)
            return null;
        slow = head;
        while (slow != fast) {
            slow = slow.next;
            fast = fast.next;
        }
        return slow;
    }
}

https://blog.csdn.net/Miss_yuki/article/details/81304107

关于环形的解析

原文地址:https://www.cnblogs.com/wangcl-8645/p/11214777.html