Construct Binary Tree from Preorder and Inorder Traversal
Given preorder and inorder traversal of a tree, construct the binary tree.
(根据先序遍历和中序遍历构建二叉树)
Example:
1. 递归
递归构建二叉树,首先根据先序遍历确定根节点,在根据中序遍历定位到根节点。其中,中序遍历根节点左边的为左子树,右边的为右子树。具体实现过程如下:
1 | # Definition for a binary tree node. |