典型的回溯算法
class Solution {
public:
vector<string> res;
vector<string> letterCasePermutation(string S) {
string path;
dfs(S,0,path);
return res;
}
void dfs(string S, int index, string path){
if(index==S.size()){
res.push_back(path);
return;
}
path.push_back(S[index]);
dfs(S,index+1,path);
path.pop_back();
if(S[index]>='a'&&S[index]<='z'){
path.push_back(S[index]-'a'+'A');
dfs(S,index+1,path);
path.pop_back();
}
if(S[index]>='A'&&S[index]<='Z'){
path.push_back(S[index]-'A'+'a');
dfs(S,index+1,path);
path.pop_back();
}
}
};