leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0784.cpp (499B)


      1 class Solution {
      2     vector<string> res;
      3 
      4     void rec(string &s, int st, string crnt) {
      5         while (st < s.size() && !isalpha(s[st]))
      6             crnt += s[st++];
      7         if (st == s.size()) {
      8             res.push_back(crnt);
      9             return;
     10         }
     11 
     12         char c = tolower(s[st]);
     13         rec(s, st + 1, crnt + c);
     14         rec(s, st + 1, crnt + (char)toupper(c));
     15     }
     16 
     17   public:
     18     vector<string> letterCasePermutation(string s) {
     19         rec(s, 0, "");
     20         return res;
     21     }
     22 };