lurenaa的博客

🥧动态规划

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Solution {
public:
int numTrees(int n) {
int tr[n + 1] = {0};
tr[0] = 1;
tr[1] = 1;
for(int i = 2; i <= n; ++i)
for(int j = 1; j <= i; ++j)
{
tr[i] += tr[j - 1] * tr[i - j];
}
return tr[n];
}
};

Accepted

19/19 cases passed (0 ms)

Your runtime beats 100 % of cpp submissions

Your memory usage beats 32.61 % of cpp submissions (8.3 MB)