LeetCode_105Construct Binary Tree from Preorder and Inorder Traversal
来源:互联网 发布:区域生长算法详解 编辑:程序博客网 时间:2024/06/12 00:54
Given preorder and inorder traversal of a tree, construct the binary tree.
public TreeNode buildTree(int[] preorder, int[] inorder) { int size = inorder.length; if(size == 0) return null; return buildNodes(preorder, inorder, 0, preorder.length-1, 0, inorder.length-1); } private TreeNode buildNodes(int[] preorder,int[] inorder,int pstart, int pend, int istart, int iend){ if (pstart > pend) return null; int point = preorder[pstart]; int i; for( i = istart;i<iend;i++){ if(inorder[i] == point){ break; } } TreeNode treeNode = new TreeNode(point); int leftSize = i - istart; treeNode.left = buildNodes(preorder, inorder, pstart+1, pstart+leftSize, istart, i-1); treeNode.right = buildNodes(preorder, inorder, pstart+leftSize+1, pend, i+1, iend); return treeNode; }
0 0
- LeetCode_105Construct Binary Tree from Preorder and Inorder Traversal
- *(leetcode) Construct Binary Tree from Preorder and Inorder Traversal (tree)
- LeetCode[Tree]: Construct Binary Tree from Preorder and Inorder Traversal
- [leetcode][tree] Construct Binary Tree from Preorder and Inorder Traversal
- Construct Binary Tree from Preorder and Inorder Traversal & Construct Binary Tree from Inorder and P
- LeetCode: Construct Binary Tree from Preorder and Inorder Traversal
- Construct Binary Tree from Preorder and Inorder Traversal
- [LeetCode]Construct Binary Tree from Preorder and Inorder Traversal
- LeetCode Construct Binary Tree from Preorder and Inorder Traversal
- [Leetcode] Construct Binary Tree from Preorder and Inorder Traversal
- Leetcode: Construct Binary Tree from Preorder and Inorder Traversal
- [LeetCode] Construct Binary Tree from Preorder and Inorder Traversal
- LeetCode Construct Binary Tree from Preorder and Inorder Traversal
- leetcode 109: Construct Binary Tree from Preorder and Inorder Traversal
- 【leetcode】Construct Binary Tree from Preorder and Inorder Traversal
- Construct Binary Tree from Preorder and Inorder Traversal
- Construct Binary Tree from Preorder and Inorder Traversal
- [LeetCode]Construct Binary Tree from Preorder and Inorder Traversal
- 欢迎使用CSDN-markdown编辑器
- Eclipse使用中的奇奇怪怪问题
- NYOJ 找数达人 (找n个数构成m是否存在)
- 浅谈数组与指针表示字符串的区别
- Android视频播放开源库vitamio
- LeetCode_105Construct Binary Tree from Preorder and Inorder Traversal
- git操作分支
- System.Configuration.ConfigurationErrorsException: An error occurred creating the configuration sect
- 注入式开发
- 继承学习日志
- 关于a标签的下载功能
- navicat的注册和安装问题
- 【二分图匹配】zoj1002Fire Net
- HTML样式以及使用