黑马程序员技术交流社区

标题: 排列组合问题 [打印本页]

作者: 笑对明天    时间: 2017-3-5 21:24
标题: 排列组合问题
M个不重复的字符,如何实现排列组合,组合成所有不重复的新字符串
作者: 小桥@    时间: 2017-3-5 22:29
字符串长度M还能做,要是0-M的排列就没辙了

作者: JINHUAN    时间: 2017-4-2 23:37
public class Test {
        public static String str = "abcd";

        public static void main(String[] args) {
                show(0, new String());
        }

        public static void show(int current_recur, String temp) {
                if (current_recur < str.length()) {
                        for (int i = 0; i < str.length(); i++) {
                                if (!(temp.contains(str.substring(i, i + 1)))) {
                                        System.out.println(temp + str.substring(i, i + 1));
                                        show(current_recur + 1, new String(temp + str.substring(i, i + 1)));
                                }
                        }
                }
        }
}




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2