CodeNinja
BAN USERJava Implementation based on this approach. Will also work if the string has numbers
public class CaseCombination {
char[] str;
public CaseCombination(char[] str){
this.str = str;
}
public static void main(String[] args){
System.out.println("Enter the string");
Scanner input = new Scanner(System.in);
String str = input.nextLine();
input.close();
CaseCombination thisObj = new CaseCombination(str.toCharArray());
printCases(thisObj, thisObj.str.length);
}
private static void printCases(CaseCombination obj, int index){
if(index == 0){
System.out.println(obj.str);
return;
}
if(Character.isAlphabetic(obj.str[index - 1])){
obj.str[index - 1] = Character.toUpperCase(obj.str[index - 1]);
printCases(obj, index-1);
obj.str[index - 1] = Character.toLowerCase(obj.str[index - 1]);
printCases(obj, index-1);
} else {
printCases(obj, index-1); // if this char is digit just recurse without generating upper and lower case
}
return;
}
}
Leetcode: 76. Minimum Window Substring
- CodeNinja January 30, 2018