mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 21:24:53 +08:00
Simplify the declarations of the Python code.
This commit is contained in:
@ -26,7 +26,7 @@ class BinarySearchTree:
|
||||
return None
|
||||
|
||||
# 将数组中间节点作为根节点
|
||||
mid: int = (start_index + end_index) // 2
|
||||
mid = (start_index + end_index) // 2
|
||||
root = TreeNode(nums[mid])
|
||||
# 递归建立左子树和右子树
|
||||
root.left = self.build_tree(
|
||||
|
||||
@ -17,7 +17,7 @@ def level_order(root: TreeNode | None) -> list[int]:
|
||||
queue: deque[TreeNode] = deque()
|
||||
queue.append(root)
|
||||
# 初始化一个列表,用于保存遍历序列
|
||||
res: list[int] = []
|
||||
res = []
|
||||
while queue:
|
||||
node: TreeNode = queue.popleft() # 队列出队
|
||||
res.append(node.val) # 保存节点值
|
||||
|
||||
Reference in New Issue
Block a user