LeeCode 106. Construct Binary Tree from Inorder and Postorder Traversal
来源:互联网 发布:众途汽修软件 编辑:程序博客网 时间:2024/06/13 10:39
Given inorder and postorder traversal of a tree, construct the binary tree.
Note:
You may assume that duplicates do not exist in the tree.
class Solution {public: TreeNode* buildTree(vector<int>& inorder, vector<int>& postorder) { return myBT2(postorder.size() - 1,postorder,0,inorder.size() - 1,inorder); } TreeNode * myBT2(int postID,vector<int>& postorder,int inID,int inEnd,vector<int>& inorder){ if(postID < 0 || inID > inEnd) return NULL; TreeNode * root = new TreeNode(postorder[postID]); int i; for(i = inID; i <= inEnd; i ++ ){ if(inorder[i] == postorder[postID]) break; } root->left = myBT2(postID - (inEnd - i) - 1 ,postorder,inID,i - 1,inorder); root->right = myBT2(postID - 1,postorder,i + 1,inEnd,inorder); return root; }};
0 0
- LeeCode 106. Construct Binary Tree from Inorder and Postorder Traversal
- leecode 解题总结: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
- 106. Construct Binary Tree from Inorder and Postorder Traversal
- 106. Construct Binary Tree from Inorder and Postorder Traversal
- 106. Construct Binary Tree from Inorder and Postorder Traversal
- 106. Construct Binary Tree from Inorder and Postorder Traversal
- 106. Construct Binary Tree from Inorder and Postorder Traversal
- Leetcode 106. Construct Binary Tree from Inorder and Postorder Traversal
- 106. Construct Binary Tree from Inorder and Postorder Traversal
- LeetCode#106. Construct Binary Tree from Inorder and Postorder Traversal
- 106. Construct Binary Tree from Inorder and Postorder Traversal
- Leetcode 106. Construct Binary Tree from Inorder and Postorder Traversal
- 106. Construct Binary Tree from Inorder and Postorder Traversal
- QT5 获取mac地址和cpu序列号
- Redis-cli命令最新总结
- java学习笔记-01
- C++将txt文件内容保存到数组
- latex2e 札记 -- No room for a new ‘thing’
- LeeCode 106. Construct Binary Tree from Inorder and Postorder Traversal
- java android 基础
- angularjs指令:replace与transclude的区别
- USB相关结构体
- JAVA何以做到“平台无关”以及JAVA的集合框架
- Tp的优缺点
- 快速Mockito教程
- 架构设计:负载均衡层设计方案(6)——Nginx + Keepalived构建高可用的负载层
- 强大的滚动控件——RecyclerView(二)横向滚动