A C++ solution Runtime: 0ms


  • 0
    P
    int numTrees(int n) {
         if(n==0) return 0;
            int s[n+1];
            int r;
            s[0] = 1;
            for(int i=1; i<n+1; i++)
            {
                s[i] = 0;
                for(int l=0; l<i; l++)
                {
                    r = i-1-l;
                    s[i] = s[i]+s[l]*s[r];
                }
            }
            return s[n];
        }

Log in to reply
 

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