Letter Case Permutation (Easy Facebook)
Input: S = "a1b2"
Output: ["a1b2", "a1B2", "A1b2", "A1B2"]
Input: S = "3z4"
Output: ["3z4", "3Z4"]
Input: S = "12345"
Output: ["12345"]Basic Idea:
class Solution { void dfs(vector<string>& res, string S, string path, int pos) { if (pos == S.size()) { res.push_back(path); return; } if (S[pos] >= 'a' && S[pos] <= 'z') dfs(res, S, path + char(S[pos] - 'a' + 'A'), pos + 1); else if (S[pos] >= 'A' && S[pos] <= 'Z') dfs(res, S, path + char(S[pos] - 'A' + 'a'), pos + 1); dfs(res, S, path + S[pos], pos + 1); } public: vector<string> letterCasePermutation(string S) { vector<string> res; dfs(res, S, "", 0); return res; } };