Concise recursive Java code by making slight modification to the previous problem.
Here I'll show you a comparison of code for Construct Binary Tree from [Problem 105: Preorder and Inorder Traversal][1] and from [Problem 106: Inorder and Posto
Here I'll show you a comparison of code for Construct Binary Tree from [Problem 105: Preorder and Inorder Traversal][1] and from [Problem 106: Inorder and Postorder Traversal][2].\n\nCode for Problem 105:\n\n\n    public static TreeNode buildTree(int[] preorder, int[] inorder) {\n        return helper(preorder, 0, inorder, 0, inorder.length - 1);\n    }\n\n    public static TreeNode helper(int[] preorder, int preStart, int[] inorder, int inStart, int inEnd) {\n        if (preStart > preorder.length - 1 || inStart > inEnd)\n            return null;\n        TreeNode root = new TreeNode(preorder[preStart]);\n        int target = inStart;\n        while (inorder[target] != preorder[preStart]) target++;\n        root.left = helper(preorder, preStart + 1, inorder, inStart, target - 1);\n        root.right = helper(preorder, preStart + target - inStart + 1, inorder, target + 1, inEnd);\n\n        return root;\n    }\n\nCode for Problem 106:\n\n\n    public static TreeNode buildTree(int[] inorder, int[] postorder) {\n        return helper(postorder, postorder.length - 1, inorder, 0, inorder.length - 1);\n    }\n\n    public static TreeNode helper(int[] postorder, int postStart, int[] inorder, int inStart, int inEnd) {\n        if (postStart < 0 || inStart > inEnd)\n            return null;\n        TreeNode root = new TreeNode(postorder[postStart]);\n        int target = inStart;\n        while (inorder[target] != postorder[postStart]) target++;\n        root.left = helper(postorder, postStart - inEnd + target - 1, inorder, inStart, target - 1);\n        root.right = helper(postorder, postStart - 1, inorder, target + 1, inEnd);\n\n        return root;\n    }\n\nNote that the only difference is, for post-order we traverse from the end of `postorder` and change the way for finding `poststart`.  \nEnjoy :)\n  [1]: https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/\n  [2]: http://Inorder%20and%20Postorder%20Traversal
[]