leetcode 105. Construct Binary Tree from Preorder and Inorder Traversal
来源:互联网 发布:优化人才培养方案 编辑:程序博客网 时间:2024/06/06 17:48
分析见:http://blog.csdn.net/kexiii/article/details/55254802
class Solution {public:TreeNode* buildTree(vector<int>& preorder, vector<int>& inorder){if (inorder.empty()){return nullptr;}auto PreIndex = 0, InIndex = 0;auto root = new TreeNode(preorder[PreIndex++]);stack<TreeNode*> stack;stack.push(root);while (true){if (stack.top()->val != inorder[InIndex]){auto p = new TreeNode(preorder[PreIndex++]);stack.top()->left = p;stack.push(p);}else{auto p = stack.top();stack.pop();InIndex++;if (InIndex == inorder.size()){break;}if (stack.size() && stack.top()->val == inorder[InIndex]){continue;}p->right = new TreeNode(preorder[PreIndex++]);stack.push(p->right);}}return root;}};
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
- Leetcode 105. Construct Binary Tree from Preorder and Inorder Traversal
- 105. Construct Binary Tree from Preorder and Inorder Traversal LeetCode
- 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
- 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
- [leetcode]105. Construct Binary Tree from Preorder and Inorder Traversal
- 浅谈java中的构造器
- 数据库dmp文件的导入导出
- MySql Host is blocked because of many connection errors;
- java日志组件(4):logback
- iOS coretext框架第三章 CTParagraphStyle类介绍
- leetcode 105. Construct Binary Tree from Preorder and Inorder Traversal
- TCP三次握手和四次挥手的全过程
- Android中的应用更新
- spring集成httpclient配置
- Atitit 图像处理类库安装与安装模式的前世今生与未来大趋势attilax总结.docx
- 测试2
- header中Content-Disposition的作用
- 手工使用Protobuf-net工具来序列化对象
- 2017~不再碎碎念