Skip to content

Instantly share code, notes, and snippets.

@gabhi
Created April 24, 2014 18:27
Show Gist options
  • Save gabhi/11264547 to your computer and use it in GitHub Desktop.
Save gabhi/11264547 to your computer and use it in GitHub Desktop.
String permutations
public static void main(String[] args) {
String input = "abcd";
permute("", input);
}
public static void permute(String prefix, String input) {
int m = prefix.length();
if (m >= 1) {
count++;
System.out.println(count + " =>" + prefix);
}
int n = input.length();
for (int i = 0; i < n; i++) {
permute(
prefix + input.charAt(i),
input.substring(0, i) + input.substring(i + 1, n));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment