Last active
September 7, 2019 00:38
-
-
Save rayning0/41ee1df7e55db7b1439cc0757b18f25c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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