26 lines
677 B
C++
26 lines
677 B
C++
|
/* 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';
|
||
|
}
|