Sharing my 0ms C++ solution


  • 0
    T
    class Solution {
    public:
        int numTrees(int n) {
            vector<int> DP(n+1, 0);
            DP[0] = 1;
            int i, j;
            for(i=1; i<=n; i++)
                for(j=1; j<=i; j++)
                    DP[i] = DP[i] + DP[j-1]*DP[i-j];
            return DP[n];
        }
    };

Log in to reply
 

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