Optimized O(n) to O(1) (#11669)

This commit is contained in:
1227haran 2024-10-02 23:37:07 +05:30 committed by GitHub
parent 00e9d86224
commit 918fa8bb8a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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