```
class Solution {
public:
int numTrees(int n) {
if(n<=0) return 0;
int all[n+1];
all[0] = 1;
all[1] = 1;
for(int i=1;i<=n;++i)
{
all[i] = 0;
for(int j=1;j<=i;++j)
all[i] += (all[i-j] * all[j-1]);
}
return all[n];
}
};
```