// https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal

# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def buildTree(self, inorder: List[int], postorder: List[int]) -> TreeNode:
        if len(inorder) == 0:
            return None
        if len(inorder) == 1:
            root = TreeNode(inorder[0])
            return root
        val = postorder[-1]
        root = TreeNode(val)
        cut = inorder.index(val)
        root.left = self.buildTree(inorder[0:cut], postorder[0:cut])
        root.right = self.buildTree(inorder[cut+1:], postorder[cut:-1])
        return root
        
        