C++ || Python || Simple Fastest Solution || with Explanation
Idea:\nThe easiest way to check if two things are shuffled versions of each other, which is what this problem is asking us to do, is to sort them both and the c
**Idea:**\nThe easiest way to check if two things are shuffled versions of each other, which is what this problem is asking us to do, is to sort them both and the compare the result.\n\nIn that sense, the easiest solution here is to do exactly that: we can convert **N** to an array of its digits, sort it, then compare that result to the result of the same process on each power of **2**.\n\nSince the constraint upon **N** is **10e9**, we only need to check powers in the range **[0,29]**.\n\nTo make things easier to compare, we can always **join()** the resulting digit arrays into strings before comparison.\n\n**C++ Code:**\nThe best result for the code below is 0ms / 5.9MB (beats 100% / 83.90%).\n```\nclass Solution {\npublic:\n    string convert(int n) {\n        string s = to_string(n);\n        sort(s.begin(), s.end());\n        return s;\n    }\n    \n    bool reorderedPowerOf2(int n) {\n        string s = convert(n);\n        for (int i = 0; i < 30; i++) {\n            if (s == convert(1 << i)) return true;\n        }\n        return false;\n    }\n};\n```\n\n**Python Code:**\nThe best result for the code below is 33ms / 14MB (beats 98.93% / 26.74%).\n```\nclass Solution:\n    def reorderedPowerOf2(self, n: int) -> bool:\n        def getConvert(n):\n            return "".join(sorted([x for x in str(n)]))\n        s = getConvert(n)\n        for i in range(30):\n            if s == getConvert(1<<i): return True\n        return False\n```
['C', 'Sorting', 'Python']