<s> """<STR_LIT>""" <EOL> __author__ = '<STR_LIT>' <EOL> class TreeNode : <EOL> def __init__ ( self , x ) : <EOL> self . val = x <EOL> self . left = None <EOL> self . right = None <EOL> class Solution : <EOL> def buildTree_MLE ( self , preorder , inorder ) : <EOL> """<STR_LIT>""" <EOL> if not preorder : <EOL> return None <EOL> root = TreeNode ( preorder [ <NUM_LIT:0> ] ) <EOL> root_index = inorder . index ( root . val ) <EOL> root . left = self . buildTree ( preorder [ <NUM_LIT:1> : root_index + <NUM_LIT:1> ] , inorder [ <NUM_LIT:0> : root_index ] ) <EOL> root . right = self . buildTree ( preorder [ root_index + <NUM_LIT:1> : ] , inorder [ root_index + <NUM_LIT:1> : ] ) <EOL> return root <EOL> def buildTree ( self , preorder , inorder ) : <EOL> """<STR_LIT>""" <EOL> self . preorder = preorder <EOL> self . inorder = inorder <EOL> return self . _buildTree ( <NUM_LIT:0> , len ( preorder ) , <NUM_LIT:0> , len ( inorder ) ) <EOL> def _buildTree ( self , pre_start , pre_end , in_start , in_end ) : <EOL> if pre_start >= pre_end : <EOL> return None <EOL> root = TreeNode ( self . preorder [ pre_start ] ) <EOL> offset = self . inorder [ in_start : in_end + <NUM_LIT:1> ] . index ( root . val ) <EOL> root . left = self . _buildTree ( pre_start + <NUM_LIT:1> , pre_start + offset + <NUM_LIT:1> , in_start , in_start + offset ) <EOL> root . right = self . _buildTree ( pre_start + offset + <NUM_LIT:1> , pre_end , in_start + offset + <NUM_LIT:1> , in_end ) <EOL> return root </s>
