C++ 100% Faster 0ms Solution by Hash
Workaround\n\nAccording to the question, we need to reorder the target number n to indicate whether the number is power of 2. That is, the count of each digit i
# **Workaround**\n\nAccording to the question, we need to reorder the target number `n` to indicate whether the number is power of 2. That is, the count of each digit in `n` must be same as the certain number which is power of 2. Therefore, we can use a custom hash function to count the digits:\n\n``` cpp\nint hashNumber(int n) {\n  auto res = int(0);              /// our result hash value.\n  while (n != 0) {                /// loop the number by taking its last digit until it becomes zero. \n    res += int(pow(10, n % 10));  /// take digit and add res by 10 ^ n.\n    n /= 10;                      /// iterate to next digit.\n  }\n  return res;\n}\n```\n\nNote for the argument `n` of function. We have constraints from the question `1 <= n <= 10^9` hence there is impossible to have a number with the count of certain digit more than `9`. We can add our result `res` by `pow(10, n%10*m)` if the count of certain digit can be increased to `m`-digits.\n\n---\n# **Constant Variable**\n\nWhen it comes to the hash values of the power of 2, it always calculate the same hash value of `1`, `2`, `4`, `8` ... etc. Hence we can memorize the hash value of these number by  `hashNumber(m)` where `1 <= m <= 10^9` and `m` is power of 2, that is, we can construct a `unordered_set` :\n\n```cpp\nauto mp     = unordered_set<int>(); /// our map which is used to store the hash value.\nauto number = int(1);               /// our iteration of power of 2.\nwhile (number <= 1e9) {             /// loop the number until it is bigger than 10^9.\n  mp.emplace(hashNumber(number));   /// insert a hash value of number into our map.\n  number <<= 1;                     /// iterate the number by multipling it by 2\n}\n```\n\nFinally, we have a constant `unordered_set`:\n``` cpp\nunordered_set<int> hashes{\n  10,         100,        10000,     100000000,  1000010,    1100,\n  1010000,    100000110,  1100100,   100110,     10111,      100010101,\n  1001010001, 1100000110, 101011010, 111001100,  2201000,    10001121,\n  1020210,    200110200,  111110011, 1010100211, 1000031011, 401001001,\n  32000120,   223100,     212010011, 120011220,  102221100,  1111101111};\n```\n\n---\n\n# **Source Code**\n\n``` cpp\nclass Solution {\nprivate:\n  inline const static unordered_set<int> hashes{\n    10,         100,        10000,     100000000,  1000010,    1100,\n    1010000,    100000110,  1100100,   100110,     10111,      100010101,\n    1001010001, 1100000110, 101011010, 111001100,  2201000,    10001121,\n    1020210,    200110200,  111110011, 1010100211, 1000031011, 401001001,\n    32000120,   223100,     212010011, 120011220,  102221100,  1111101111};\n\n  int hashNumber(int n) {\n    auto res = int(0);\n    while (n != 0) {\n      res += int(pow(10, n % 10));\n      n /= 10;\n    }\n    return res;\n  }\n\npublic:\n  bool reorderedPowerOf2(int n) {\n    return hashes.find(hashNumber(n)) != hashes.end();\n  }\n};\n```\n# **Complexity**\n\n- **Time**: `O(number_of_digits(n))`\n- **Space**: `O(1)`\n\n![image](https://assets.leetcode.com/users/images/24a1f710-c749-478e-9fc9-49c0285789f9_1661494383.20038.png)\n\n\n
['C']