首页
学习
活动
专区
工具
TVP
发布
您找到你想要的搜索结果了吗?
是的
没有找到

Construct Binary Tree from Preorder and Inorder Traversal Construct Bina

链接:https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/description...Construct Binary Tree from Preorder and Inorder Traversal Given preorder and inorder traversal of a tree...思路:首先,你应该知道 前序遍历:根节点,左子树,右子树; 中序遍历:左子树,根节点,右子树; 所以,我们可以从preorder中找到整棵树的根节点,即为preorder[0],由于preorder...和inorder是对同一棵树的遍历,我们可以知道preorder[0]在inorder中一定也存在,不妨设preorder[0]==inorder[k]。...并且,我们已经知道了根节点左子树的节点数(与中序遍历长度相同),不妨设为l,我们可以知道preorder从1到l+1就是根节点左子树的前序遍历,剩下的最后一部分就是根节点右子树的前序遍历。

30740
领券