mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-23 21:11:08 +00:00
Optimized O(n) to O(1) (#11669)
This commit is contained in:
parent
00e9d86224
commit
918fa8bb8a
|
@ -14,11 +14,11 @@ class Node:
|
|||
|
||||
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
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user