Skip to content

Commit 876e204

Browse files
authored
Create Letter Case Permutation.cpp
1 parent fc5f545 commit 876e204

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* Leet Code */
2+
/* Title - Letter Case Permutation */
3+
/* Created By - Akash Modak */
4+
/* Date - 07/06/2023 */
5+
6+
// Given a string s, you can transform every letter individually to be lowercase or uppercase to create another string.
7+
8+
// Return a list of all possible strings we could create. Return the output in any order.
9+
10+
11+
12+
// Example 1:
13+
14+
// Input: s = "a1b2"
15+
// Output: ["a1b2","a1B2","A1b2","A1B2"]
16+
// Example 2:
17+
18+
// Input: s = "3z4"
19+
// Output: ["3z4","3Z4"]
20+
21+
class Solution {
22+
public:
23+
void perm(vector<string> &res, string s, int i){
24+
if(i==s.length()){
25+
res.push_back(s);
26+
return;
27+
}else if(isalpha(s[i])){
28+
s[i]=tolower(s[i]);
29+
perm(res,s,i+1);
30+
s[i]=toupper(s[i]);
31+
perm(res,s,i+1);
32+
}else{
33+
perm(res,s,i+1);
34+
}
35+
36+
}
37+
vector<string> letterCasePermutation(string s) {
38+
vector<string> res;
39+
perm(res,s,0);
40+
return res;
41+
}
42+
};

0 commit comments

Comments
 (0)