Java | DFS | Beats > 97% | Clean code
Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\n Add your space complexity here, e.g. O(n) \n\n# Co
# Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n  int i;\n  Map<Integer, Integer> map = new HashMap<>();\n\n  private TreeNode buildTree(int[] postorder, int l, int r) {\n    if (l > r) return null;\n\n    var m = map.get(postorder[i]);\n    var node = new TreeNode(postorder[i--]);\n\n    node.right = buildTree(postorder, m+1, r);\n    node.left = buildTree(postorder, l, m-1);\n\n    return node;\n  }\n\n  public TreeNode buildTree(int[] inorder, int[] postorder) {\n    for (var i=0; i < inorder.length; i++)\n      map.put(inorder[i], i);\n    \n    i = postorder.length - 1;\n    return buildTree(postorder, 0, inorder.length - 1);\n  }\n}\n```
['Depth-First Search', 'Recursion', 'Binary Tree', 'Java']