Java/Linked List Cycle.java
<reponame>Kyrylo-Ktl/LeetCode-Solutions<filename>Java/Linked List Cycle.java<gh_stars>0public class Solution {

    /**
     * Time:   O(n)
     * Memory: O(1)
     */
    public boolean hasCycle(ListNode head) {
        ListNode slow = head, fast= head;

        while (fast != null && fast.next != null) {
            slow = slow.next;
            fast = fast.next;

            if (slow == fast)
                return true;
        }

        return false;
    }
}
