Skip to content

Instantly share code, notes, and snippets.

@qiaoxu123
Last active December 5, 2018 08:29
Show Gist options
  • Save qiaoxu123/fcfb61225b75961e59d54c21cf3f503b to your computer and use it in GitHub Desktop.
Save qiaoxu123/fcfb61225b75961e59d54c21cf3f503b to your computer and use it in GitHub Desktop.
Given a string S, we can transform every letter individually to be lowercase or uppercase to create another string. Return a list of all possible strings we could create. ``` Examples: Input: S = "a1b2" Output: ["a1b2", "a1B2", "A1b2", "A1B2"] Inpu
class Solution {
public:
vector<string> letterCasePermutation(string S) {
vector<string> vs;
helper(vs,S,0);
return vs;
}
void helper(vector<string> & vs,string &S,int p){
if(p == S.size()){
vs.push_back(S);
return;
}
if(S[p] >= '0' && S[p] <= '9')
helper(vs,S,p+1);
else if(S[p] >= 'a' && S[p] <= 'z'){
helper(vs,S,p+1);
S[p] += 'A' - 'a';
helper(vs,S,p+1);
}
else if(S[p] >= 'A' && S[p] <= 'Z'){
helper(vs,S,p+1);
S[p] += 'a' - 'A';
helper(vs,S,p+1);
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment