<p>You are given an integer <code>n</code>. We reorder the digits in any order (including the original order) such that the leading digit is not zero.</p>

<p>Return <code>true</code> <em>if and only if we can do this so that the resulting number is a power of two</em>.</p>

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

<pre>
<strong>Input:</strong> n = 1
<strong>Output:</strong> true
</pre>

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

<pre>
<strong>Input:</strong> n = 10
<strong>Output:</strong> false
</pre>

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

<ul>
	<li><code>1 &lt;= n &lt;= 10<sup>9</sup></code></li>
</ul>

#include <algorithm>
#include <string>
#include <unordered_set>

class Solution {
public:
    bool reorderedPowerOf2(int n) {
        // Create a string of the digits of n and sort it
        std::string n_str = std::to_string(n);
        std::sort(n_str.begin(), n_str.end());
        
        // Precompute all powers of 2 that fit within the range 1 <= n <= 10^9
        std::unordered_set<std::string> powers_of_two;
        for (int i = 1; i <= 1e9; i <<= 1) {
            std::string power_of_two_str = std::to_string(i);
            std::sort(power_of_two_str.begin(), power_of_two_str.end());
            powers_of_two.insert(power_of_two_str);
        }
        
        // Check if the sorted digits of n match any sorted power of 2
        return powers_of_two.find(n_str) != powers_of_two.end();
    }
};
10000