Simple python solution

  • 3
    class Solution(object):
    def generateTrees(self, n):
        return[i for i in xrange(1, n+1)])
    def cal(self, lst):
        if not lst: return [None]
        for i in xrange(len(lst)):
            for left in[:i]):
                for right in[i+1:]):
                    node, node.left, node.right=TreeNode(lst[i]), left, right
        return res

Log in to reply

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