105. Construct Binary Tree from Preorder and Inorder Traversal
来源:互联网 发布:苹果mac自有办公软件 编辑:程序博客网 时间:2024/06/03 07:44
class Solution {public: TreeNode* buildTree(vector<int>& preorder, vector<int>& inorder) { if(0 == preorder.size() || 0 == inorder.size()) return NULL; return build(preorder, inorder, 0, inorder.begin(), inorder.end()); } TreeNode *build(vector<int>& preorder, vector<int>& inorder, int rootPreIndex, vector<int>::iterator Instart, vector<int>::iterator Inend) { if(rootPreIndex >= preorder.size() || Inend <= Instart) return NULL; auto target = find(Instart, Inend, preorder[rootPreIndex]); if(target != inorder.end()){ TreeNode *root = new TreeNode(preorder[rootPreIndex]); root->left = build(preorder, inorder, rootPreIndex+1, Instart, target); root->right = build(preorder, inorder, rootPreIndex + target - Instart + 1, target+1, Inend); return root; } else{ return NULL; } }};
阅读全文
0 0
- LeetCode 105. Construct Binary Tree from Preorder and Inorder Traversal
- [Leetcode] 105. Construct Binary Tree from Preorder and Inorder Traversal
- LeetCode --- 105. Construct Binary Tree from Preorder and Inorder Traversal
- [LeetCode]*105.Construct Binary Tree from Preorder and Inorder Traversal
- [leetcode] 105.Construct Binary Tree from Preorder and Inorder Traversal
- 105. Construct Binary Tree from Preorder and Inorder Traversal
- 105. Construct Binary Tree from Preorder and Inorder Traversal
- 105. Construct Binary Tree from Preorder and Inorder Traversal
- 105. Construct Binary Tree from Preorder and Inorder Traversal
- 105. Construct Binary Tree from Preorder and Inorder Traversal
- 105. Construct Binary Tree from Preorder and Inorder Traversal
- Leetcode 105. Construct Binary Tree from Preorder and Inorder Traversal
- 105. Construct Binary Tree from Preorder and Inorder Traversal LeetCode
- 105. Construct Binary Tree from Preorder and Inorder Traversal
- LeetCode#105. Construct Binary Tree from Preorder and Inorder Traversal
- 105. Construct Binary Tree from Preorder and Inorder Traversal
- Leetcode 105. Construct Binary Tree from Preorder and Inorder Traversal
- 105. Construct Binary Tree from Preorder and Inorder Traversal
- js函数式编程
- java编程中遇到的时区与时间问题总结
- HDU
- C语言排序之堆排序篇
- Qt Creator使用
- 105. Construct Binary Tree from Preorder and Inorder Traversal
- 将数据库中的数据导入Solr索引库
- (十五)PathMeasure
- CT图之cnn
- [PHP]PhpStorm搭建PHP环境及PHP.ini丢失问题
- Marjar Cola
- Java键盘事件
- [USACO3.3]商店购物 Shopping Offers
- 实现多系统网络yum服务器和客户端配置