-
Notifications
You must be signed in to change notification settings - Fork 2
/
784LetterCasePermutation.py
45 lines (39 loc) · 1010 Bytes
/
784LetterCasePermutation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
class Solution:
def letterCasePermutation(self, S: str) -> List[str]:
res = ['']
for char in S:
if char.isalpha():
res *= 2
for i in range(len(res)):
if i < len(res)/2:
res[i] += char.lower()
else:
res[i] += char.upper()
else:
for j in range(len(res)):
res[j] += char
return res
##############################
############for c++###########
##############################
'''
class Solution {
public:
vector<string> res;
vector<string> letterCasePermutation(string S) {
dfs(S, 0);
return res;
}
void dfs(string S, int u) {
if (u == S.size()) {
res.push_back(S);
return;
}
dfs(S, u+1);
if (S[u] >= 'A') {
S[u] ^= 32;
dfs(S, u+1);
}
}
};
'''