solution.cpp 270 字节
Newer Older
每日一练社区's avatar
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <stdc++.h>
using namespace std;
class Solution
{
public:
	int numTrees(int n)
	{
		vector<int> sum(n + 1);
		sum[0] = 1;
		for (int i = 1; i <= n; i++)
		{
			for (int j = 0; j < i; j++)
			{
				sum[i] += sum[j] * sum[i - j - 1];
			}
		}
		return sum[n];
	}
}