mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 21:24:53 +08:00
fine tune
This commit is contained in:
@ -16,7 +16,7 @@ class GraphAdjList:
|
||||
def __init__(self, edges: list[list[Vertex]]):
|
||||
"""构造方法"""
|
||||
# 邻接表,key: 顶点,value:该顶点的所有邻接顶点
|
||||
self.adj_list = dict[Vertex, Vertex]()
|
||||
self.adj_list = dict[Vertex, list[Vertex]]()
|
||||
# 添加所有顶点和边
|
||||
for edge in edges:
|
||||
self.add_vertex(edge[0])
|
||||
|
||||
@ -92,7 +92,7 @@ class HashMapChaining:
|
||||
|
||||
"""Driver Code"""
|
||||
if __name__ == "__main__":
|
||||
# 测试代码
|
||||
# 初始化哈希表
|
||||
hashmap = HashMapChaining()
|
||||
|
||||
# 添加操作
|
||||
|
||||
@ -35,7 +35,7 @@ class TreeNode:
|
||||
|
||||
def list_to_tree_dfs(arr: list[int], i: int) -> TreeNode | None:
|
||||
"""将列表反序列化为二叉树:递归"""
|
||||
# 如果索引超出数组长度,或者对应的元素为 None,返回 None
|
||||
# 如果索引超出数组长度,或者对应的元素为 None ,则返回 None
|
||||
if i < 0 or i >= len(arr) or arr[i] is None:
|
||||
return None
|
||||
# 构建当前节点
|
||||
|
||||
Reference in New Issue
Block a user