Design Patter 11: Subsets | Problem: Letter Case Permutations
parent
55ca543bdc
commit
4ab2448243
@ -0,0 +1,26 @@
|
||||
/* Problem: https://leetcode.com/problems/letter-case-permutation/
|
||||
*/
|
||||
|
||||
#include "lib_leetcode.h"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
std::vector<std::string> solution(const std::string input) {
|
||||
std::vector<std::string> perms = {""};
|
||||
for (const char c : input) {
|
||||
for (std::size_t i = 0, upto = perms.size(); i < upto; i++) {
|
||||
if (std::isalpha(c))
|
||||
perms.push_back(perms[i] + (char)std::toupper(c));
|
||||
perms[i] += std::tolower(c);
|
||||
}
|
||||
}
|
||||
return perms;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::cout << solution("a1b2") << '\n'
|
||||
<< solution("3z4") << '\n'
|
||||
<< solution("mQe") << '\n'
|
||||
<< solution("03fH") << '\n';
|
||||
}
|
Loading…
Reference in New Issue