Leetcode 784 Letter casePermutation

image

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Solution {
public:
vector<string> letterCasePermutation(string S) {
vector<string> ss;
dfs(S,0,ss);
return ss;
}
private:
void dfs(string &s,int k,vector<string> &ss){
if(k==s.length()) {
ss.push_back(s);//!!
return;
}
dfs(s,k+1,ss);//!!
if(!isalpha(s[k])) return;
else{
s[k]^=1<<5;
dfs(s,k+1,ss);
s[k]^=1<<5;

}
}
};