C++ 0ms Solution | Easy to understand | Short code
1) Create a vector of strings "v" of size 30 where each string represents a power of 2 (from 0 to 30) with its digits in sorted form.\n2) Convert the given numb
1) Create a vector of strings "v" of size 30 where each string represents a power of 2 (from 0 to 30) with its digits in sorted form.\n2) Convert the given number to string "s" and sort its digits as well.\n3) Compare the resultant string "s" with each element of the vector of strings "v".\n4) Return true if a match is found else return false.\n\n```\nclass Solution {\npublic:\n    bool reorderedPowerOf2(int n) {\n        vector<string> v;\n        for(int i=0;i<30;i++)\n        {\n            int k=pow(2,i);\n            string c=to_string(k);\n            sort(c.begin(),c.end());\n            v.push_back(c);\n        }\n        string s=to_string(n);\n        sort(s.begin(),s.end());\n        for(auto it:v)\n        {\n            if(s==it)\n                return true;\n        }\n        return false;\n    }\n};\n```\n
['Math', 'String', 'C', 'Sorting']