classSolution:# @paramn n: An integer# @return: A list of rootdefgenerateTrees(self,n):# write your code herereturnself.dfs(1,n)defdfs(self,start,end):ifstart>end:return[None]res=[]forrootvalinrange(start,end+1):LeftTree=self.dfs(start,rootval-1)RightTree=self.dfs(rootval+1,end)foriinLeftTree:forjinRightTree:root=TreeNode(rootval)root.left=iroot.right=jres.append(root)returnres