[LeetCode]Construct Binary Tree from Inorder and Postorder Traversal
来源:互联网 发布:mysql update 多表 编辑:程序博客网 时间:2024/05/17 05:12
Given inorder and postorder traversal of a tree, construct the binary tree.
Note:
You may assume that duplicates do not exist in the tree.
/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution {public TreeNode buildTree(int[] inorder, int[] postorder) { return buildTree(inorder,postorder,0,inorder.length-1,0,postorder.length-1);}private TreeNode buildTree(int []inorder, int []postorder,int inst,int inend,int postst, int postend){if(inst>inend||postst>postend||inorder.length<1){return null;}TreeNode tn =new TreeNode(postorder[postend]); int index = Arrays.binarySearch(inorder, inst, inend+1, postorder[postend]);tn.left = buildTree(inorder,postorder,inst,inst+index-1,postst,postst+index-inst-1);tn.right = buildTree(inorder,postorder,index+1,inend,postst+index-inst,postend-1);return tn;}}
0 0
- *(leetcode) Construct Binary Tree from Inorder and Postorder Traversal (tree)
- LeetCode[Tree]: 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] 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
- [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
- Pyton的类特性
- 分布式异步消息框架构建笔记 1—— 设想
- C++ str系列函数 (包含strtok用法)
- SecureCRT的快捷键
- iOS自定义日期picker选择器,参考他人代码...
- [LeetCode]Construct Binary Tree from Inorder and Postorder Traversal
- jmeter试用记录-参数化和关联
- Android requires compiler compliance level 5.0 or 6.0. Found '1.7' instead.报错!
- linux设备树dts之powerpc 平台解析过程
- 高效effective C++ 55条款之个人学习笔记二
- 我的c语言
- 几种序列化之间的比较Thrift&protocolbuffer&avro
- 范围说明例子
- activity属性总结