CodeFreak

Sigin/Signup with Google

def detectCycle(head):

hare, tortoise = head, head

while tortoise != None and hare != None or hare != tortoise:

hare, tortoise = hare.next.next, tortoise.next

return tortoise

Run
Submit