You are viewing a single comment's thread. Return to all comments →
Use a number usually is not a good idea, you may can consider using a new list to contian the data that has been already traversed. Check the code,
def has_cycle(head): alist = [] while head.next is not None: if head.data not in alist: alist.append(head.data) head = head.next else: return True 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 →
Use a number usually is not a good idea, you may can consider using a new list to contian the data that has been already traversed. Check the code,