Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit dec7504

Browse files
Add C++ implementation
Signed-off-by: begeekmyfriend <begeekmyfriend@gmail.com>
1 parent ced1a26 commit dec7504

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <stdc++.h>
2+
3+
using namespace std;
4+
5+
/*
6+
* f(n) = f(0)f(n-1) + f(1)f(n-2) + ... + f(n-2)f(1) + f(n-1)f(0)
7+
*/
8+
class Solution {
9+
public:
10+
int numTrees(int n) {
11+
vector<int> sum(n + 1);
12+
sum[0] = 1;
13+
for (int i = 1; i <= n; i++) {
14+
for (int j = 0; j < i; j++) {
15+
sum[i] += sum[j] * sum[i - j - 1];
16+
}
17+
}
18+
return sum[n];
19+
}
20+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /