Construct Binary Tree from Inorder and Postorder Traversal
Solution Code
class Solution:def buildTree(self, inorder: List[int], postorder: List[int]) -> Optional[TreeNode]:idx_map = {val: i for i, val in enumerate(inorder)}def helper(in_left, in_right):if in_left > in_right: return Noneval = postorder.pop()root = TreeNode(val)index = idx_map[val]root.right = helper(index + 1, in_right)root.left = helper(in_left, index - 1)return rootreturn helper(0, len(inorder) - 1)Time Complexity
O(N)
Space Complexity
O(N)

