Skip to content

Instantly share code, notes, and snippets.

@AnasAboreeda
Created January 24, 2022 10:38
Show Gist options
  • Save AnasAboreeda/40506821f8d1e6faaed1a183e754b6b7 to your computer and use it in GitHub Desktop.
Save AnasAboreeda/40506821f8d1e6faaed1a183e754b6b7 to your computer and use it in GitHub Desktop.
class Permutation {
void permutation(String str) {
permutation(str, "");
}
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);
permutation(rem, prefix + str.charAt(i));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment