public class Cyclic { public static void main(String[] args) { } public static boolean isCyclic(Node head) { if (head == null || head.next == null) { return false; } Node slow = head; Node fast = head.next.next; while (slow != null && fast != null && fast.next != null) { if (slow.value == fast.value) { return true; } } return false; } }