[LinkedIn] String Permutation

print all permutation of strings
From Here

public static void permutation(String str) { 
    permutation("", str); 
}

private static void permutation(String prefix, String str) {
    int n = str.length();
    if (n == 0) System.out.println(prefix);
    else {
        for (int i = 0; i < n; i++)
            permutation(prefix + str.charAt(i), str.substring(0, i) + str.substring(i+1, n));
    }
}
posted on 2015-04-02 04:23  Seth_L  阅读(102)  评论(0编辑  收藏  举报