diff --git a/cpp/2210/221030-CN.cpp b/cpp/2210/221030-CN.cpp new file mode 100644 index 0000000..db540d9 --- /dev/null +++ b/cpp/2210/221030-CN.cpp @@ -0,0 +1,31 @@ +#include +#include +#include + +/** + * 784. Letter Case Permutation + * + * 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. + */ + +class Solution { +public: + std::vector letterCasePermutation(std::string& s) { + std::vector ret; + std::function f = [&](int pos) { + if (pos >= s.length()) { + ret.push_back(s); + } else if (std::isalpha(s[pos])) { + s[pos] = std::tolower(s[pos]); + f(1 + pos); + s[pos] = std::toupper(s[pos]); + f(1 + pos); + } else { + f(1 + pos); + } + }; + f(0); + return ret; + } +};