Using Combinatorics


#1

long int catalan( int n) {
if (n <= 1){
return 1;
}
long int result = 0;
for (int i=0; i<n; i++){
result += catalan(i)*catalan(n-i-1);
}
return result;
}
int Solution::numTrees(int A) {
return catalan(A);
}

learn more