My simple solution


  • 0
    V
    class Solution {
    public:
        int numTrees(int n) {
            int sum;
            vector<int> temp;
            temp.push_back( 1 );
            for( int i = 1; i <= n; i++ )
            {
                sum = 0;
                for( int j = 1; j <= i; j++ )
                    sum += temp[ j - 1 ] * temp[ i - j ];
                
                temp.push_back( sum );
            }
            return temp[ n ];
        }
    };

  • 0
    L
    This post is deleted!

Log in to reply
 

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