Cannot make a static reference to the non-static method numTrees(int) from the type Solution

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?
2026年09月20日 04:53
有1个网友回答
网友(1):

肯定的了,你的main是static方法的了,你的那个又是普通的方法的了,要是static的方法的了,另外你的递归好像蛮复杂的了,回答完毕的了