You are viewing a single comment's thread. Return to all comments →
My python submission not taking into account the information that the list has at most 100 items:
def has_cycle(head): visited_map = {} current = head while current.next is not None: if current in visited_map: return True visited_map[current] = True current = current.next return False
Chose to perform the lookup on a map instead of a list because maps have O(1) time complexity instead of O(n) for the list.
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 →
My python submission not taking into account the information that the list has at most 100 items:
Chose to perform the lookup on a map instead of a list because maps have O(1) time complexity instead of O(n) for the list.