LeetCode---(106)Construct Binary Tree from Inorder and Postorder Traversal
来源:互联网 发布:陕师大网络教育平台 编辑:程序博客网 时间:2024/05/22 01:57
Given inorder and postorder traversal of a tree, construct the binary tree.
Note:
You may assume that duplicates do not exist in the tree.
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: TreeNode* help(vector<int>& inorder, vector<int>& postorder,int fromi,int fromp,int length) { if(length==0) return 0; TreeNode* root=new TreeNode(postorder[fromp+length-1]); int i; for(i=fromi;inorder[i]!=postorder[fromp+length-1];i++) ; root->left=help(inorder,postorder,fromi,fromp,i-fromi); root->right=help(inorder,postorder,i+1,fromp+i-fromi,length-1-i+fromi); return root; } TreeNode* buildTree(vector<int>& inorder, vector<int>& postorder) { return help(inorder,postorder,0,0,inorder.size()); }};
0 0
- LeetCode 106: Construct Binary Tree from Inorder and Postorder Traversal
- LeetCode(106)Construct Binary Tree from Inorder and Postorder Traversal
- LeetCode: Construct Binary Tree from Inorder and Postorder Traversal [106]
- LeetCode 106 Construct Binary Tree from Inorder and Postorder Traversal
- LeetCode 106 Construct Binary Tree from Inorder and Postorder Traversal
- [leetcode 106] Construct Binary Tree from Inorder and Postorder Traversal
- [LeetCode 106]Construct Binary Tree from Inorder and Postorder Traversal
- leetcode || 106、Construct Binary Tree from Inorder and Postorder Traversal
- Construct Binary Tree from Inorder and Postorder Traversal - LeetCode 106
- LeetCode 106:Construct Binary Tree from Postorder and Inorder Traversal
- LeetCode---(106)Construct Binary Tree from Inorder and Postorder Traversal
- LeetCode(106) Construct Binary Tree from Inorder and Postorder Traversal
- Leetcode #106 Construct Binary Tree from Inorder and Postorder Traversal
- leetcode 106: Construct Binary Tree from Inorder and Postorder Traversal
- LeetCode 106: Construct Binary Tree from Inorder and Postorder Traversal
- 【LEETCODE】106-Construct Binary Tree from Inorder and Postorder Traversal
- LeetCode 106 Construct Binary Tree from Inorder and Postorder Traversal
- 【leetcode】【106】Construct Binary Tree from Inorder and Postorder Traversal
- Windows程序设计学习笔记(五)——菜单资源和加速键的使用
- WebService大讲堂之Axis2(2):复合类型数据的传递
- javaScript基础概念整理1(数据类型)
- mysql5.1.73配置主从服务器
- 关于中文乱码问题
- LeetCode---(106)Construct Binary Tree from Inorder and Postorder Traversal
- 学习笔记---在Activity被回收时
- ArrayAdapter中的android.R.id.text1是什么
- python字符串/元组/列表/字典互转
- c++三种野指针
- 变量和运算符的使用、JAVA控制语句
- iOS开发---绘图
- android studio 更新 Gradle错误解决方法
- HDU-1166-敌兵布阵-单点更新