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));
}
}
Apart from coding and design interview questions, this page contains updates on my learnings with Java. It helps me organize my learning. Read about my future self here : https://siliconvalleystories.blogspot.com/
Monday, 9 April 2012
Generate all permutations of a string in Java
Subscribe to:
Post Comments (Atom)
thanks for your solution.Here is another way to implement this http://techno-terminal.blogspot.in/2015/09/java-program-to-compute-all-permutation.html
ReplyDelete