use set for visited

This commit is contained in:
onyx-and-iris 2024-01-11 18:54:08 +00:00
parent 10914ee208
commit 6301018adc
2 changed files with 4 additions and 4 deletions

View File

@ -21,7 +21,7 @@ graph = {
"f": [],
}
visited = []
visited = set()
def bfs():
@ -36,7 +36,7 @@ def bfs():
if current_node.name in visited:
continue
visited.append(current_node.name)
visited.add(current_node.name)
next_nodes = graph[current_node.name]
for node in next_nodes:

View File

@ -21,7 +21,7 @@ graph = {
"bat": [],
}
visited = []
visited = set()
def bfs():
@ -36,7 +36,7 @@ def bfs():
if current_node.name in visited:
continue
visited.append(current_node.name)
visited.add(current_node.name)
next_nodes = graph[current_node.name]
for node in next_nodes: