What's wrong with my code?

  • 0
    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 = []
            return res

Log in to reply

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