You are viewing a single comment's thread. Return to all comments →
I just tried to add a identifier for each node which can be accessed with O(1) complexity with the help of dictionaries
def has_cycle(head): visited = {} while head: visited[head]=1 if visited.get(head.next,0) != 0: return True head = head.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 →
I just tried to add a identifier for each node which can be accessed with O(1) complexity with the help of dictionaries