Last active
April 17, 2016 19:56
-
-
Save deyindra/537bedb8077540e0e836b2dbed1e28d6 to your computer and use it in GitHub Desktop.
String Permutation and Combinarion
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 characters
public static void generatePermutation(String str, final int index, final String prefix, List<String> list, | |
final char[] allChars, final char replaceAbleChar){ | |
if(str.equals("")){ | |
list.add(prefix); | |
}else{ | |
char[] array = str.toCharArray(); | |
if(array[index]!=replaceAbleChar){ | |
generatePermutation(str.substring(index+1),0,prefix+array[index],list,allChars,replaceAbleChar); | |
}else{ | |
for(char ch:allChars){ | |
generatePermutation(str.substring(index+1),0,prefix+ch,list,allChars,replaceAbleChar); | |
} | |
} | |
} | |
} | |
public static List<String> generatePermutation(String str, | |
char[] allChars, char replaceAbleChar){ | |
List<String> list = new ArrayList<>(); | |
generatePermutation(str, 0,"", list, allChars, replaceAbleChar); | |
return list; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment