题目:输入字符串,输出该字符串的全排列。
样例:输入"abc",输出"abc,acb,bac,bca,cba,cab"
解法1:递归输出
private static void stringPermutation(char[] str, int from, int to) {
if (str == null || str.length == 0) {
return;
}
if (from == to) {
System.out.println(String.valueOf(str));
} else {
for (int i = from; i < to; i++) {
swap(str, from, i);
stringPermutation(str, from + 1, to);
swap(str, from, i);
}
}
}