You are viewing a single comment's thread. Return to all comments →
def has_cycle(head): slow = head fast = head
while fast != None and fast.next != None: slow = slow.next fast = fast.next.next if slow == fast: return 1 # Cycle detected return 0 # No cycle
Seems like cookies are disabled on this browser, please enable them to open this website
Cycle Detection
You are viewing a single comment's thread. Return to all comments →
def has_cycle(head): slow = head fast = head