Given preorder and inorder traversal of a tree, construct the binary tree.
Note:
You may assume that duplicates do not exist in the tree.
TreeNode* build(vector<int> &preorder,int left1,int right1,vector<int> &inorder,int left2,int right2)
{
if(right1-left1 != right2-left2)return NULL;
if(right1>=preorder.size() || right2>=inorder.size())return NULL;
if(left1==right1 && left2==right2)
{
TreeNode* root = new TreeNode(preorder[left1]);
......
阅读全文