Skip to content

Commit 3bfdd67

Browse files
committed
Add 96-UniqueBinarySearchTrees.cpp
1 parent 281eca1 commit 3bfdd67

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution {
2+
public:
3+
long long numTrees(long long n) {
4+
5+
if(n <= 1){return 1;}
6+
std::vector<long long> f(n + 1, 0);
7+
f[0] = f[1] = 1;
8+
for(int p = 2; p <= n; p++){for(int q = 0; q < p; q++){f[p] += f[q] * f[p - 1 - q];}}
9+
return f[n];
10+
}
11+
};

0 commit comments

Comments
 (0)