Last active
December 10, 2015 19:18
Revisions
-
gpaulu revised this gist
Jan 8, 2013 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -25,6 +25,7 @@ public LinkedHashSet<String> getPurmutations(){ } public void run(){ recPerms("",s); found = true; } private void recPerms(String begin, String end){ if(end.isEmpty()){ -
gpaulu created this gist
Jan 8, 2013 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,48 @@ import java.util.LinkedHashSet; public class Permutation { private LinkedHashSet<String> set; private String s; private boolean found; Permutation(String s){ this.s = s; found = false; set = new LinkedHashSet<String>(); } Permutation(String s, boolean run){ this(s); if(run) run(); } public LinkedHashSet<String> getPurmutations(){ if(found) return set; else{ run(); return set; } } public void run(){ recPerms("",s); } private void recPerms(String begin, String end){ if(end.isEmpty()){ set.add(begin); } else{ for(int i=0; i<end.length();i++){ recPerms(begin + String.valueOf(end.charAt(i)),end.substring(0, i)+end.substring(i+1)); } } } @Override public String toString(){ if(found) return set.toString(); else{ run(); return set.toString(); } } }