Cannot make a static reference to the non-static method numTrees(int) from the type Solution
publicclassSolution{/***@paramargs*/publicstaticvoidmain(String[]args){//TODOAuto-gen...
public class Solution {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(numTrees(8));
}
public int numTrees(int n){
if(n==0||n==1)
return 1;
else{
int sum=0;
int left=0;
int right=0;
for(int k=1;k<=n;k++){
left=numTrees(k-1);
right=numTrees(n-k);
sum+=left*right;
}
return sum;
}
}
}
how to solve the problems? 展开
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(numTrees(8));
}
public int numTrees(int n){
if(n==0||n==1)
return 1;
else{
int sum=0;
int left=0;
int right=0;
for(int k=1;k<=n;k++){
left=numTrees(k-1);
right=numTrees(n-k);
sum+=left*right;
}
return sum;
}
}
}
how to solve the problems? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询