We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Well, I didn't know the floyd algo... I could only think of using a Hashset. I don't know if it's allowed to import java.utils, but things becomes insanely easy if you switch to python.
def HasCycle(head):
nodes = set()
while (head != None):
if (head in nodes):
return 1
nodes.add(head)
head = head.next
return 0
Cycle Detection
You are viewing a single comment's thread. Return to all comments →
Well, I didn't know the floyd algo... I could only think of using a Hashset. I don't know if it's allowed to import java.utils, but things becomes insanely easy if you switch to python.