Given inorder and postorder traversal of a tree, construct the binary tree.
Note:
You may assume that duplicates do not exist in the tree.
class Solution(object):
def buildTree(self, inorder, postorder):
i = inorder
p = postorder
if i:
val = p.pop()
pos = i.index(val)
root = TreeNode(val)
root.right = self.buildTree(i[pos+1:],p)
root.left = self.buildTree(i[:pos],p)
return root