Skip to content

Instantly share code, notes, and snippets.

@rayning0
Last active September 7, 2019 00:38
Show Gist options
  • Save rayning0/41ee1df7e55db7b1439cc0757b18f25c to your computer and use it in GitHub Desktop.
Save rayning0/41ee1df7e55db7b1439cc0757b18f25c to your computer and use it in GitHub Desktop.
class Example12 {
public static void permutation(String str) {
permutation(str, "");
}
public static void permutation(String str, String prefix) {
if (str.length() == 0) {
System.out.println(prefix);
} else {
for (int i = 0; i < str.length(); i++) {
String rem = str.substring(0, i) + str.substring(i + 1);
System.out.println(i + " " + str.substring(0, i) + " " + str.substring(i + 1));
permutation(rem, prefix + str.charAt(i));
}
}
}
public static void main(String args[]) {
permutation("cat");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment