unique-binary-search-trees-ii

class Solution {
public:
    vector generateTrees(int n) {
        return create(1,n);
    }
    vectorcreate(int L,int R)
    {
        vectorres;
        if(L>R)
        {
            res.push_back(NULL);
            return res;
        }
        for(int i=L;i<=R;i++)
        {
            vectorLeft=create(L,i-1);
            vectorRight=create(i+1,R);
            for(auto j:Left)
            {
                for(auto k:Right)
                {
                    TreeNode*root=new TreeNode(i);
                    root->left=j,root->right=k;
                    res.push_back(root);
                }
            }
        }
        return res;
    }
};

你可能感兴趣的:(unique-binary-search-trees-ii)