class Solution {
public:
void permutationHelper(int pos, string S, string chosen, vector<string> & res){
if (chosen.size()==S.size()){
res.push_back(chosen);
return;
}
char c = S[pos];
if (isalpha(c)){
chosen.push_back(tolower(c));
permutationHelper(pos+1, S, chosen, res);
chosen.pop_back();
chosen.push_back(toupper(c));
permutationHelper(pos+1, S, chosen, res);
chosen.pop_back();
}
else {
chosen.push_back(c);
permutationHelper(pos+1, S, chosen, res);
chosen.pop_back();
}
}
vector<string> letterCasePermutation(string S) {
vector<string> res;
permutationHelper(0, S, "", res);
return res;
}
};
Updated 20180919... Reunderstand choose + explore + unchoose.
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.