You are viewing a single comment's thread. Return to all comments →
Then store the node address? My solution works on the test cases. Have a look?
def has_cycle(head): if head is None: return False visited = [] node = head flag = 99 while node is not None: if node not in visited: visited.append(node) else: flag = 1 return True node = node.next if flag==99: return False
Worst case here will be O(n^2) right?
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 →
Then store the node address? My solution works on the test cases. Have a look?
Worst case here will be O(n^2) right?