package problems; public class LeetCode142 { public ListNode detectCycle(ListNode head) { ListNode fast = head, slow = head; while (true) { if(fast == null || fast.next == null) { return null; } fast = fast.next.next; slow = slow.next; if(fast == slow) break; } fast = head; while (slow != fast) { slow = slow.next; fast = fast.next; } return fast; } } class LeetCode142_1{ public ListNode detectCycle(ListNode head) { return null; } }