Skip to content

Latest commit

 

History

History
21 lines (17 loc) · 394 Bytes

File metadata and controls

21 lines (17 loc) · 394 Bytes

Linked List Cycle

Solution 1

public class Solution {
    public boolean hasCycle(ListNode head) {
        ListNode slow = head, fast = head;

        while (fast != null && fast.next != null) {
            slow = slow.next;
            fast = fast.next.next;
            if (slow == fast) {
                return true;
            }
        }

        return false;
    }
}