<p>Given a string <code>s</code>, you&nbsp;can transform every letter individually to be lowercase or uppercase to create another string.</p>

<p>Return <em>a list of all possible strings we could create</em>. Return the output in <strong>any order</strong>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;a1b2&quot;
<strong>Output:</strong> [&quot;a1b2&quot;,&quot;a1B2&quot;,&quot;A1b2&quot;,&quot;A1B2&quot;]
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;3z4&quot;
<strong>Output:</strong> [&quot;3z4&quot;,&quot;3Z4&quot;]
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= s.length &lt;= 12</code></li>
	<li><code>s</code> consists of lowercase English letters, uppercase English letters, and digits.</li>
</ul>

class Solution {
public:
    
    bool is_lower(char c){
        return c>='a'&&c<='z';
    }
    bool is_upper(char c){
        return c>='A'&&c<='Z';
    }
    bool is_letter(char c){
        return is_lower(c)||is_upper(c);
    }

    vector<string> letterCasePermutation(string s) {
        vector<string> res;
        res = helper(s);
        unordered_set<string> st(res.begin(), res.end());
        vector<string> ans(st.begin(), st.end());
        return ans;
    }

    vector<string> helper(string s){
        vector<string> res;      
        if (s.length()==1) {
            res.push_back(s);
            if (is_lower(s[0])){
                transform(s.begin(), s.end(), s.begin(), ::toupper);
            }
            else{
                transform(s.begin(), s.end(), s.begin(), ::tolower);
            }
            res.push_back(s);
            return res;
        }
        auto following = helper(s.substr(1));
   
        char c = s[0]; 
        if (is_letter(s[0])){
            
            if (is_lower(s[0])){
                c = toupper(s[0]);
            }
            else{
                c = tolower(s[0]);
            }
            
        }
        for (auto p2: following){
            res.push_back(s[0]+p2);
            if (c!=s[0]){
                res.push_back(c+p2);
            }
        }
        
        return res;
    }
};
17200