What's wrong with my code?


  • 0
    X
    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

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.