借楼,请问大家这种解法是否可行? public static int dfsSolution(int n, int m, int[] birthYear, int x){ if(birthYear==null || birthYear.length==0) return x>m?0:n; //for later O(1) find HashSet<Integer> set=new HashSet<>(); for(int b: birthYear){ set.add(b); } return dfs(n,m,set,0,0, x); } public static int dfs(int n, int m, HashSet<Integer> set, int cur_year, int age, int x){ if(cur_year>=x) { if(age<=m){ return set.contains(age)?2*n:n; } return 0; } if(age>m) return 0; //if it is in the birth year if(set.contains(age)){ //这一批海豚今年会生n个宝宝,从0岁开始算.另开一个分支计算 return dfs(n,m,set,cur_year+1,age+1, x)+dfs(n,m,set, cur_year+1,1,x); } return dfs(n,m,set,cur_year+1,age+1, x); }