1 Star 0 Fork 0

蓝桥云课/python-100

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
042-graph_path.py 687 Bytes
一键复制 编辑 原始数据 按行查看 历史
xiaoyi733112 提交于 2020-02-20 17:17 . python-100 answer
from graph import Graph, State
from collections import deque
class GraphPathExists(Graph):
def path_exists(self, start, end):
if start is None or end is None:
return False
if start is end:
return True
queue = deque()
queue.append(start)
start.visit_state = State.visited
while queue:
node = queue.popleft()
if node is end:
return True
for adj_node in node.adj_nodes.values():
if adj_node.visit_state == State.unvisited:
queue.append(adj_node)
adj_node.visit_state = State.visited
return False
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/lanqiao-courses/python-100.git
git@gitee.com:lanqiao-courses/python-100.git
lanqiao-courses
python-100
python-100
master

搜索帮助