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": [],
|
"f": [],
|
||||||
}
|
}
|
||||||
|
|
||||||
visited = []
|
visited = set()
|
||||||
|
|
||||||
|
|
||||||
def bfs():
|
def bfs():
|
||||||
@ -36,7 +36,7 @@ def bfs():
|
|||||||
|
|
||||||
if current_node.name in visited:
|
if current_node.name in visited:
|
||||||
continue
|
continue
|
||||||
visited.append(current_node.name)
|
visited.add(current_node.name)
|
||||||
|
|
||||||
next_nodes = graph[current_node.name]
|
next_nodes = graph[current_node.name]
|
||||||
for node in next_nodes:
|
for node in next_nodes:
|
||||||
|
@ -21,7 +21,7 @@ graph = {
|
|||||||
"bat": [],
|
"bat": [],
|
||||||
}
|
}
|
||||||
|
|
||||||
visited = []
|
visited = set()
|
||||||
|
|
||||||
|
|
||||||
def bfs():
|
def bfs():
|
||||||
@ -36,7 +36,7 @@ def bfs():
|
|||||||
|
|
||||||
if current_node.name in visited:
|
if current_node.name in visited:
|
||||||
continue
|
continue
|
||||||
visited.append(current_node.name)
|
visited.add(current_node.name)
|
||||||
|
|
||||||
next_nodes = graph[current_node.name]
|
next_nodes = graph[current_node.name]
|
||||||
for node in next_nodes:
|
for node in next_nodes:
|
||||||
|
Loading…
Reference in New Issue
Block a user