forked from USPCodeLabSanca/dev.hire-2021
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path784.cpp
More file actions
31 lines (25 loc) · 969 Bytes
/
784.cpp
File metadata and controls
31 lines (25 loc) · 969 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
class Solution {
public:
vector<string> letterCasePermutation(string s) {
vector<string> allPermutations;
this->permutate(0, s.length(), s, allPermutations);
return allPermutations;
}
void permutate(int i, int n, string& currentString, vector<string>& allPermutations) {
if (i == n) {
allPermutations.push_back(currentString);
return;
}
if (isalpha(currentString[i])) {
string lowerCase(currentString);
string upperCase(currentString);
lowerCase[i] = tolower(currentString[i]);
upperCase[i] = toupper(currentString[i]);
// Generate next permutations
this->permutate(i + 1, n, lowerCase, allPermutations);
this->permutate(i + 1, n, upperCase, allPermutations);
} else {
this->permutate(i + 1, n, currentString, allPermutations);
}
}
};