mirror of
https://github.com/onyx-and-iris/grokking-algorithms.git
synced 2024-11-15 17:30:52 +00:00
use set for visited
This commit is contained in:
parent
10914ee208
commit
6301018adc
@ -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:
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user