<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:
    char flip(int c) {
        if (c >= 65 && c <= 90) {
            return (char)tolower(c);
        }
        else if (c >= 97 && c <= 122) {
            return (char)toupper(c);
        }
        return '0';
    }
    vector<string> letterCasePermutation(string s) {
        int n = s.size();
        set<string> res;
        for (int i = pow(2, n); i < pow(2,n+1); i++) {
            string bitmask = bitset<32>(i).to_string().substr(32-n);
            string temp = s;
            for (int i = 0; i < bitmask.size(); i++) {
                char c = bitmask[i];
                if (c == '1') {
                    char flipped = flip(temp[i]);
                    if (flipped != '0') {
                        temp[i] = flipped;
                    }
                }
            }
            res.insert(temp);
        }
        return vector<string>(res.begin(), res.end());
    }
};
16500