本文主要是介绍106. Construct Binary Tree from Inorder and Postorder Traversal【M】【31】,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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 = inorderp = postorderif 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
这篇关于106. Construct Binary Tree from Inorder and Postorder Traversal【M】【31】的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!