Skip to content

Instantly share code, notes, and snippets.

@gabhi
Created June 26, 2014 23:29
Show Gist options
  • Save gabhi/e3ed4220c13f4b071abc to your computer and use it in GitHub Desktop.
Save gabhi/e3ed4220c13f4b071abc to your computer and use it in GitHub Desktop.
String permutations Java
public class StringPermutations {
public static void main(String[] args) {
permuteString("abc");
}
private static void permuteString(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));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment