Skip to content

Commit 341d7ef

Browse files
committed
docs: update a description of the solution to lcof problem: No.07
面试题07. 重建二叉树
1 parent cb90316 commit 341d7ef

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lcof/面试题07. 重建二叉树/README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@
3434

3535
## 解法
3636

37-
前序序列的第一个结点 `preorder[0]` 为根节点,我们在中序序列中找到根节点的位置 i,可以将中序序列划分为左子树 `inorder[:i]` 、右子树 `inorder[i+1:]`
37+
前序序列的第一个结点 `preorder[0]` 为根节点,我们在中序序列中找到根节点的位置 `i`,可以将中序序列划分为左子树 `inorder[:i]` 和右子树 `inorder[i + 1:]`
3838

3939
通过左右子树的区间,可以计算出左、右子树节点的个数,假设为 m、n。然后在前序节点中,从根节点往后的 m 个节点为左子树,再往后的 n 个节点为右子树。
4040

4141
递归求解即可。
4242

43-
> 前序遍历:先遍历根节点,再遍历左右子树;中序遍历:先遍历左子树,再遍历根节点,最后遍历右子树。
43+
> 前序遍历:先遍历根节点,再遍历左子树,最后遍历右子树;
44+
>
45+
> 中序遍历:先遍历左子树,再遍历根节点,最后遍历右子树。
4446
4547
<!-- tabs:start -->
4648

0 commit comments

Comments
 (0)