text: class Solution:
      def buildTree(self, preorder, inorder):
          if not preorder:
              return None
          root = TreeNode(preorder[0])
          i = inorder.index(root.val)
          root.left = self.buildTree(preorder[1 : i + 1], inorder[:i])
          root.right = self.buildTree(preorder[i + 1 :], inorder[i + 1 :])
          return root
  