題目:輸入字符串累提,輸出該字符串的全排列喷户。
樣例:輸入"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);
}
}
}