Update the Optional alias of Python codes.

This commit is contained in:
Yudong Jin
2023-01-09 02:49:34 +08:00
parent 4d01436138
commit 97ee638d31
8 changed files with 37 additions and 45 deletions

View File

@@ -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
# 访问优先级:左子树 -> 右子树 -> 根结点