public List<String> letterCasePermutation(String S) {
List<String> res = new LinkedList<>();
dfs("", S, res, 0);
return res;
}
public void dfs(String pre, String S, List<String> res, int index) {
System.out.println(pre+"-----------");
// 判斷結束的條件,因為沒有for循環是以隻能這麼判斷
if (index == S.length())
res.add(pre);
else {
//System.out.println(pre + "//////////////" + index);
char ch = S.charAt(index);
// 指定這是一個字母啊,就是數字,
if (!Character.isLetter(ch))
dfs(pre + ch, S, res, index + 1);
else {
// System.out.println("xiaoxie");
// 将字元參數轉化為小寫的
ch = Character.toLowerCase(ch);
dfs(pre + ch, S, res, index + 1);
// System.out.println("===========" + index);
// 将字元參數轉化為大寫的
ch = Character.toUpperCase(ch);
dfs(pre + ch, S, res, index + 1);
}
}
}