Last active
December 5, 2018 08:29
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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