You are viewing a single comment's thread. Return to all comments →
Here's one way to do it in Python3:
def has_cycle(head): slowPointer = head fastPointer = head while fastPointer and fastPointer.next: if slowPointer == fastPointer: return True slowPointer = slowPointer.next fastPointer = fastPointer.next.next return False
Seems like cookies are disabled on this browser, please enable them to open this website
Linked Lists: Detect a Cycle
You are viewing a single comment's thread. Return to all comments →
Here's one way to do it in Python3: