真心觉得这个递归还是很麻烦的。
public static void doit(String a,String b,int k){
if(a.length()==k){
System.out.println(a); //当选出的字符串与原字符串长度相同时打印
}else{
for(int i = 0; i< b.length(); i++){ //C31*C21*C11排列;
String tempa = new String(a);
String tempb = new String(b);
doit(tempa+tempb.charAt(i),new StringBuilder(tempb).deleteCharAt(i).toString(),a.length()+b.length()); //递归调用
}
}
}
public static void main(String[] args) {
String str = "abc";
doit("",str,str.length());
}
本文探讨了使用递归算法解决字符串组合问题的过程,详细解释了如何通过递归调用和字符串操作实现特定条件下的字符串生成。
499

被折叠的 条评论
为什么被折叠?



