如何找出给定高度 h 的所有BST的数量,并且在给定唯一数字集合中丢弃高于h的所有BST?
我已经使用递归方法编写了代码。
static int bst(int h,int n){
if(h==0&&n==0)return 1;
else if(h==0&&n==1)return 1;
else if(h==0&&n>1)return 0;
else if(h>0&&n==0)return 1;
else{
int sum=0;
for(int i=1;i<=n;i++)
sum+=bst(h-1,i-1)*bst(h-1,n-i);
return sum;
}
}