Leetcode 800 Solution
This article provides solution to leetcode question 800 (letter-case-permutation)
Access this page by simply typing in "lcs 800" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/letter-case-permutation
Solution
class Solution {
vector<string> ans;
public:
void _letterCasePermutation(string& S, int i) {
if (i == S.size())
{
ans.push_back(S);
return;
}
_letterCasePermutation(S, i + 1);
char ch = S[i];
if (ch >= 'a' && ch <= 'z')
S[i] = S[i] + 'A' - 'a';
else if (ch >= 'A' && ch <= 'Z')
S[i] = S[i] - 'A' + 'a';
else
return;
_letterCasePermutation(S, i + 1);
S[i] = ch;
}
vector<string> letterCasePermutation(string S) {
_letterCasePermutation(S, 0);
return ans;
}
};