leetcode 日经贴,Cpp code -Construct Binary Tree from Inorder and Postorder Traversal
来源:互联网 发布:淘宝客服退款中心 编辑:程序博客网 时间:2024/06/05 23:02
Construct Binary Tree from Inorder and Postorder Traversal
/** * 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* build(int *post, int *in, int n) { if (n <= 0) { return NULL; } TreeNode *r = new TreeNode(post[n - 1]); int p = 0; while (p < n && in[p] != post[n - 1]) { ++p; } if (p > n) { //error return r; } r->left = build(post, in, p); r->right = build(post + p, in + 1 + p, n - p - 1); } TreeNode* buildTree(vector<int>& inorder, vector<int>& postorder) { if (postorder.size() != inorder.size() || postorder.empty()) { return NULL; } return build(&postorder[0], &inorder[0], postorder.size()); }};
0 0
- leetcode 日经贴,Cpp code -Construct Binary Tree from Inorder and Postorder Traversal
- CODE 27: Construct Binary Tree from Inorder and Postorder Traversal
- [leet code] Construct Binary Tree from Inorder and Postorder Traversal
- construct-binary-tree-from-inorder-and-postorder-traversal Java code
- *(leetcode) Construct Binary Tree from Inorder and Postorder Traversal (tree)
- LeetCode[Tree]: Construct Binary Tree from Inorder and Postorder Traversal
- leetcode 日经贴,Cpp code -Construct Binary Tree from Preorder and Inorder Traversal
- LeetCode: Construct Binary Tree from Inorder and Postorder Traversal
- [LeetCode]Construct Binary Tree from Inorder and Postorder Traversal
- LeetCode Construct Binary Tree from Inorder and Postorder Traversal
- LeetCode: Construct Binary Tree from Inorder and Postorder Traversal
- LeetCode: Construct Binary Tree from Inorder and Postorder Traversal
- [LeetCode] Construct Binary Tree from Inorder and Postorder Traversal
- LeetCode Construct Binary Tree from Inorder and Postorder Traversal
- [Leetcode] Construct Binary Tree from Inorder and Postorder Traversal
- leetcode 110: Construct Binary Tree from Inorder and Postorder Traversal
- 【leetcode】Construct Binary Tree from Inorder and Postorder Traversal
- [LeetCode]Construct Binary Tree from Inorder and Postorder Traversal
- 模拟新浪微博随便看看
- Android UI性能优化实战
- Chapter3:插入排序
- XML/Json解析成对象 对象序列号成xml/Json
- poj151 Atlantics 扫描线+线段树+离散化
- leetcode 日经贴,Cpp code -Construct Binary Tree from Inorder and Postorder Traversal
- 链接href='/'表示指向根目录
- codeforces #301 D
- 清空JS数组中的空值
- POJ 1330 最近公共祖先LCA(Tarjan离线做法)
- Chapter3:选择排序
- Chapter3:对象排序
- Matlab的矩阵存储和opencv mat的区别
- 南北车跌停 投资人回归P2P网贷