Created
April 24, 2014 18:27
-
-
Save gabhi/11264547 to your computer and use it in GitHub Desktop.
String permutations
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
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