Skip to content

Commit

Permalink
Optimized O(n) to O(1) (#11669)
Browse files Browse the repository at this point in the history
  • Loading branch information
1227haran authored Oct 2, 2024
1 parent 00e9d86 commit 918fa8b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions data_structures/linked_list/has_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ def __init__(self, data: Any) -> None:

def __iter__(self):
node = self
visited = []
visited = set()
while node:
if node in visited:
raise ContainsLoopError
visited.append(node)
visited.add(node)
yield node.data
node = node.next_node

Expand Down

0 comments on commit 918fa8b

Please sign in to comment.