<s> class TreeNode : <EOL> def __init__ ( self , x ) : <EOL> self . val = x <EOL> self . left = None <EOL> self . right = None <EOL> def __repr__ ( self ) : <EOL> if self : <EOL> serial = [ ] <EOL> queue = [ self ] <EOL> while queue : <EOL> cur = queue [ <NUM_LIT:0> ] <EOL> if cur : <EOL> serial . append ( cur . val ) <EOL> queue . append ( cur . left ) <EOL> queue . append ( cur . right ) <EOL> else : <EOL> serial . append ( "<STR_LIT:#>" ) <EOL> queue = queue [ <NUM_LIT:1> : ] <EOL> while serial [ - <NUM_LIT:1> ] == "<STR_LIT:#>" : <EOL> serial . pop ( ) <EOL> return repr ( serial ) <EOL> else : <EOL> return None <EOL> class Solution : <EOL> def generateTrees ( self , n ) : <EOL> return self . generateTreesRecu ( <NUM_LIT:1> , n ) <EOL> def generateTreesRecu ( self , low , high ) : <EOL> result = [ ] <EOL> if low > high : <EOL> result . append ( None ) <EOL> for i in xrange ( low , high + <NUM_LIT:1> ) : <EOL> left = self . generateTreesRecu ( low , i - <NUM_LIT:1> ) <EOL> right = self . generateTreesRecu ( i + <NUM_LIT:1> , high ) <EOL> for j in left : <EOL> for k in right : <EOL> cur = TreeNode ( i ) <EOL> cur . left = j <EOL> cur . right = k <EOL> result . append ( cur ) <EOL> return result <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> print Solution ( ) . generateTrees ( <NUM_LIT:3> ) </s>
