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.
It's probably a good idea to use sets instead of arrays for lookups since the difference is O(n) vs O(1) lookup time. It doesn't matter for the size in this problem, but it'll make a difference in problems with larger input sizes.
Cycle Detection
You are viewing a single comment's thread. Return to all comments →
visited = set()
It's probably a good idea to use sets instead of arrays for lookups since the difference is
O(n)
vsO(1)
lookup time. It doesn't matter for the size in this problem, but it'll make a difference in problems with larger input sizes.