标签:
public class Solution { public TreeNode buildTree(int[] inorder, int[] postorder) { return helper(inorder, postorder, 0, inorder.length - 1, 0, postorder.length - 1); } public TreeNode helper(int[] inorder, int[] postorder, int l1, int r1, int l2, int r2) { if (l1 > r1) { return null; } TreeNode root = new TreeNode(postorder[r2]); int i = 0; for (; i + l1 < r1; i++) { if (inorder[i + l1] == root.val) { break; } } root.left = helper(inorder, postorder, l1, l1 + i - 1, l2, l2 + i - 1); root.right = helper(inorder, postorder, l1 + i + 1, r1, l2 + i, r2 - 1); return root; } }
[LeetCode]Construct Binary Tree from Inorder and Postorder Traversal
标签:
原文地址:http://www.cnblogs.com/vision-love-programming/p/5021044.html