```
class Solution:
# @param {integer} n
# @return {TreeNode[]}
def generateTrees(self, n):
def dfs(start,end):
if start > end: return None
for rootval in range(start,end+1):
left = dfs(start,rootval-1)
right = dfs(rootval+1,end)
for i in left:
for j in right:
root = TreeNode(rootval)
root.left = i
root.right = j
res.append(root)
res = []
dfs(1,n)
return res
```