c++ solution


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

Log in to reply
 

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