Quick Math
The main idea is what powers of 2 look like in binary form:\n\n\n\nthis will help easily iterate over all powers of two\n\nSo all we need is to convert n to sor
The main idea is what powers of 2 look like in binary form:\n\n<img width="200" src="https://assets.leetcode.com/users/images/ae9964b4-ffbd-40a5-a934-e3dc1de49d28_1661482426.3498342.png">\n\nthis will help easily iterate over all powers of two\n\nSo all we need is to convert n to sorted digits and then compare them with the sorted digits for each power of two.\n`n <= 10e9`, we only need to check powers in the range `[0,29]`\n\na little explanation of how the shift operation `<< `works: \n\n<img src="https://assets.leetcode.com/users/images/df39060e-624d-4fb8-abe2-e3f1da6d0bf9_1661486107.3084147.png">\n\n\n##### Java\n\n```java\npublic boolean reorderedPowerOf2(int n) {\n        char[] number = sortedDigits(n);\n\n        for (int i = 0; i < 30; ++i) {\n            char[] powerOfTwo = sortedDigits(1 << i);\n            if (Arrays.equals(number, powerOfTwo))\n                return true;\n        }\n        return false;\n    }\n\n    private char[] sortedDigits(int n) {\n        char[] digits = String.valueOf(n).toCharArray();\n        Arrays.sort(digits);\n        return digits;\n    }\n```\n\n##### C++\n\n```\npublic:\n    bool reorderedPowerOf2(int n) {\n        string number = sortedDigits(n);\n\n        for (int i = 0; i < 30; ++i) {\n            string powerOfTwo = sortedDigits(1 << i);\n            if (number == powerOfTwo)\n                return true;\n        }\n\n        return false;\n    }\n\nprivate:\n    string sortedDigits(int n) {\n        string digits = to_string(n);\n        sort(digits.begin(), digits.end());\n        return digits;\n    }\n```\n\n##### Python\n```python\ndef reorderedPowerOf2(self, n: int) -> bool:\n        digits = Counter(str(n))\n        \n        for i in range(30):\n            powerOfTwo = str(1 << i)\n            if digits == Counter(powerOfTwo):\n                return True\n        return False\n```\n\nMy repositories with leetcode problems solving - [Java](https://github.com/FLlGHT/algorithms/tree/master/j-algorithms/src/main/java),  [C++](https://github.com/FLlGHT/algorithms/tree/master/c-algorithms/src/main/c%2B%2B)\n
['C', 'Python', 'Java']