142. Linked List Cycle II
chromat..(hjroh0315)
2023-03-09 23:33
추천 0
# @param {ListNode} head
# @return {ListNode}
def detectCycle
(head
)
begin
t=head.
next
h=head.
next.
next
while t!=h
t=t.
next
h=h.
next.
next
end
t=head
while t!=h
t=t.
next
h=h.
next
end
t
rescue NoMethodError
nil
end
endFloyd's Cycle Detection Algorithm
댓글 0