-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathLetterCasePermutation.cpp
74 lines (70 loc) · 1.75 KB
/
LetterCasePermutation.cpp
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
class Solution {
public:
vector<string> lcp(string s){
if(s.size()==1)
{
if(isalpha(s[0]))
{
char ch;
vector<string>ans;
if(islower(s[0])){
ch=toupper(s[0]);
}else{
ch=tolower(s[0]);
}
string f(1,s[0]);
string fr(1,ch);
ans.push_back(f);
ans.push_back(fr);
return ans;
}
else
{
vector<string>ans;
string f(1,s[0]);
ans.push_back(f);
return ans;
}
}
string str;
for(int i=1;i<s.size();i++)
{
str.push_back(s[i]);
}
vector<string>v=lcp(str);
char c=s[0];
vector<string>ans;
if(isalpha(c)){
for(auto val:v)
{
string f(1,c);
ans.push_back(f+val);
}
char ch;
if(islower(s[0])){
ch=toupper(s[0]);
}else{
ch=tolower(s[0]);
}
for(auto val:v)
{
string f(1,ch);
ans.push_back(ch+val);
}
return ans;
}
else
{
for(auto val:v)
{
string f(1,c);
ans.push_back(f+val);
}
return ans;
}
}
vector<string> letterCasePermutation(string s) {
vector<string>ans=lcp(s);
return ans;
}
};