判断链表是否有环

private boolean slowAndFastSolution(ListNode head) {
    if (head == null) {
        return false;
    }
    ListNode slow = head;
    ListNode fast = head.next;
    while (fast != null && fast.next != null) {
        if (slow.equals(fast)) {
            return true;
        }
        slow = slow.next;
        fast = fast.next.next;
    }

    return false;
}
原文地址:https://www.cnblogs.com/zzq-include/p/13584990.html