142. Linked List Cycle2
Linked List Cycle II - LeetCode
Submit Code
def detectCycle(head) catchup_node = find_catchup_node(head) return nil if catchup_node.nil?
fast = catchup_node slow = head
while fast != slow fast = fast.next slow = slow.next end
fastend
def find_catchup_node(head) fast = slow = head
while fast && fast.next fast = fast.next.next slow = slow.next
if fast == slow return fast end end
nilend