8000 1 · javasharper/leetcode@27b21ea · GitHub
[go: up one dir, main page]

Skip to content

Commit 27b21ea

Browse files
committed
1
1 parent a7ff7fe commit 27b21ea

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public:
3+
int numTrees(int n) {
4+
// Start typing your C/C++ solution below
5+
// DO NOT write int main() function
6+
7+
vector<int> dp(n + 1, 0);
8+
dp[0] = dp[1] = 1;
9+
for (int i = 2; i <= n; i++) {
10+
for (int j = 0; j < i; j++)
11+
dp[i] += dp[j] * dp[i-j-1];
12+
}
13+
return dp[n];
14+
}
15+
};

0 commit comments

Comments
 (0)
0