We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Cycle Detection
- Discussions
Cycle Detection
Cycle Detection
Sort by
recency
|
32 Discussions
|
Please Login in order to post a comment
Only python works for me...
Floyd cycle approach
static boolean hasCycle(SinglyLinkedListNode head) { if (head == null || head.next == null) { return false; } SinglyLinkedListNode slow = head; SinglyLinkedListNode fast = head.next; while (fast != null && fast.next != null) { if (slow == fast) { return true; } slow = slow.next; fast = fast.next.next; } return false; }
C++
C# Solution: