-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathletterCasePermutation.cpp
More file actions
42 lines (39 loc) · 961 Bytes
/
Copy pathletterCasePermutation.cpp
File metadata and controls
42 lines (39 loc) · 961 Bytes
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
#include <bits/stdc++.h>
using namespace std;
// Letter Case Permutation
class Solution
{
public:
void traverse(string &s, int i, vector<string> &ans, string res = "")
{
if (i == s.size())
{
ans.push_back(res);
return;
}
if (s[i] >= '0' && s[i] <= '9')
return traverse(s, i + 1, ans, res + s[i]);
else
{
traverse(s, i + 1, ans, res + s[i]);
if (s[i] >= 'A' && s[i] <= 'Z')
traverse(s, i + 1, ans, res + char(s[i] + 32));
else
traverse(s, i + 1, ans, res + char(s[i] - 32));
}
}
vector<string> letterCasePermutation(string S)
{
vector<string> ans;
traverse(S, 0, ans);
return ans;
}
};
int main()
{
string s;
cin >> s;
vector<string> perm = Solution().letterCasePermutation(s);
for (string word : perm)
cout << word << " ";
}