# Definition for a binary tree node # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution: # @param inorder, a list of integers # @param postorder, a list of integers # @return a tree node def buildTree(self, inorder, postorder): if not inorder: return None root=TreeNode(postorder[-1]) rootidx=inorder.index(postorder[-1]) root.left=self.buildTree(inorder[:rootidx],postorder[:rootidx]) root.right=self.buildTree(inorder[1+rootidx:],postorder[rootidx:-1]) return root
Friday, September 12, 2014
Leetcode: Construct Binary Tree from Inorder and Postorder Traversal @Python
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment