{ "question_id": 234859, "question_title": "用0到9生成十位数的所有排列组合", "question_content": "用 0到9 生成 十位数的所有排列组合,数字0不能在第一个,这个生成的十位数,不能有重复的数字。\n", "difficulty": "简单", "answer_id": 212594, "answer_content": "\n\n```\n public static void main(String[] args) {\n\t\tString str[] = { \"0\", \"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\" };\n\t\tpermutation(str, 0, str.length);\n\t}\n\n\tstatic void swap(String[] str, int start, int end) {\n\t\tString tmep = str[start];\n\t\tstr[start] = str[end];\n\t\tstr[end] = tmep;\n\t}\n\n\tstatic void permutation(String[] str, int start, int end) {\n\n\t\tif (start == end - 1) {\n\t\t\tfor (int i = 0; i < end; i++) {\n\t\t\t\tSystem.out.print(str[i]);\n\t\t\t}\n\t\t\tSystem.out.println();\n\t\t} else {\n\n\t\t\tfor (int i = start; i < end; i++) {\n\t\t\t\tif (i == 0 && str[0].equals(\"0\"))\n\t\t\t\t\tcontinue;\n\t\t\t\tswap(str, start, i);\n\t\t\t\tpermutation(str, start + 1, end);\n\n\t\t\t\tswap(str, start, i);\n\t\t\t}\n\t\t}\n\t}\n}\n```\n\n", "tag_name": "java", "java": "class java_234859 {\n public static void main(String[] args) {\n\t String str[] = { \"0\", \"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\" };\n\t permutation(str, 0, str.length);\n }\n static void swap(String[] str, int start, int end) {\n\t String tmep = str[start];\n\t str[start] = str[end];\n\t str[end] = tmep;\n }\n static void permutation(String[] str, int start, int end) {\n\t if (start == end - 1) {\n\t\t for (int i = 0; i < end; i++) {\n\t\t\tSystem.out.print(str[i]);\n\t\t }\n\t\t System.out.println();\n\t } else {\n\t\t for (int i = start; i < end; i++) {\n\t\t\tif (i == 0 && str[0].equals(\"0\"))\n\t\t\t continue;\n\t\t\tswap(str, start, i);\n\t\t\tpermutation(str, start + 1, end);\n\t\t\tswap(str, start, i);\n\t\t }\n\t }\n }\n}", "topic_link": "https://bbs.csdn.net/topics/600470287", "status": 1, "keywords": "图算法,算法高阶,最小生成树,最小生成树的形成", "license": "csdn.net", "notebook": { "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/25.ipynb?type=file" }, "notebook_enable": 1 }