Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
407 B
1
Indexable
Never
class Solution(object):
    def buildTree(self, preorder, inorder):
        """
        :type preorder: List[int]
        :type inorder: List[int]
        :rtype: TreeNode
        """
        def build(pre, ino):
            if ino:
                idx = ino.index(pre.pop(0))
                return TreeNode(ino[idx], build(pre, ino[0:idx]), build(pre, ino[idx+1:]))
        return build(preorder, inorder)
Leave a Comment