-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathLetter Case Permutation.cpp
42 lines (33 loc) · 967 Bytes
/
Letter Case Permutation.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
/* Leet Code */
/* Title - Letter Case Permutation */
/* Created By - Akash Modak */
/* Date - 07/06/2023 */
// Given a string s, you can transform every letter individually to be lowercase or uppercase to create another string.
// Return a list of all possible strings we could create. Return the output in any order.
// Example 1:
// Input: s = "a1b2"
// Output: ["a1b2","a1B2","A1b2","A1B2"]
// Example 2:
// Input: s = "3z4"
// Output: ["3z4","3Z4"]
class Solution {
public:
void perm(vector<string> &res, string s, int i){
if(i==s.length()){
res.push_back(s);
return;
}else if(isalpha(s[i])){
s[i]=tolower(s[i]);
perm(res,s,i+1);
s[i]=toupper(s[i]);
perm(res,s,i+1);
}else{
perm(res,s,i+1);
}
}
vector<string> letterCasePermutation(string s) {
vector<string> res;
perm(res,s,0);
return res;
}
};