Skip to content

Instantly share code, notes, and snippets.

@Ipseeta
Created May 16, 2017 08:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ipseeta/d8c5138867cf2617f5da107b97c9254e to your computer and use it in GitHub Desktop.
Save Ipseeta/d8c5138867cf2617f5da107b97c9254e to your computer and use it in GitHub Desktop.
public class StringPermutation {
public static void main(String[] args) {
perm("123");
}
private static void perm(String str){
perm("",str);
}
private static void perm(String prefix, String str) {
if(null!=str){
int n = str.length();
if(n == 0) System.out.println(prefix);
else{
for(int i=0;i<n;i++){
perm(prefix + str.charAt(i), str.substring(0, i)+str.substring(i+1, n));
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment