mirror of
https://github.com/krahets/hello-algo.git
synced 2025-12-19 07:17:54 +08:00
Update the Optional alias of Python codes.
This commit is contained in:
@@ -66,7 +66,7 @@ comments: true
|
||||
|
||||
```python title="binary_tree_bfs.py"
|
||||
""" 层序遍历 """
|
||||
def hier_order(root: TreeNode):
|
||||
def hier_order(root: Optional[TreeNode]):
|
||||
# 初始化队列,加入根结点
|
||||
queue = collections.deque()
|
||||
queue.append(root)
|
||||
@@ -277,7 +277,7 @@ comments: true
|
||||
|
||||
```python title="binary_tree_dfs.py"
|
||||
""" 前序遍历 """
|
||||
def pre_order(root: typing.Optional[TreeNode]):
|
||||
def pre_order(root: Optional[TreeNode]):
|
||||
if root is None:
|
||||
return
|
||||
# 访问优先级:根结点 -> 左子树 -> 右子树
|
||||
@@ -286,7 +286,7 @@ comments: true
|
||||
pre_order(root=root.right)
|
||||
|
||||
""" 中序遍历 """
|
||||
def in_order(root: typing.Optional[TreeNode]):
|
||||
def in_order(root: Optional[TreeNode]):
|
||||
if root is None:
|
||||
return
|
||||
# 访问优先级:左子树 -> 根结点 -> 右子树
|
||||
@@ -295,7 +295,7 @@ comments: true
|
||||
in_order(root=root.right)
|
||||
|
||||
""" 后序遍历 """
|
||||
def post_order(root: typing.Optional[TreeNode]):
|
||||
def post_order(root: Optional[TreeNode]):
|
||||
if root is None:
|
||||
return
|
||||
# 访问优先级:左子树 -> 右子树 -> 根结点
|
||||
|
||||
Reference in New Issue
Block a user