[C++/Python]  Direct simulation & Indirect checking all possibilities of Power of 2
Idea1:  Direct simulation of Permutations [1]\nIntuition\n\nFor each permutation of the digits of N, let\'s check if that permutation is a power of 2.\n\nAlgori
Idea1:  Direct simulation of Permutations [1]\nIntuition\n\nFor each permutation of the digits of N, let\'s check if that permutation is a power of 2.\n\nAlgorithm\n\nThis approach has two steps: how will we generate the permutations of the digits, and how will we check that the permutation represents a power of 2?\n\nTo generate permutations of the digits, we place any digit into the first position (start = 0), then any of the remaining digits into the second position (start = 1), and so on. In Python, we can use the builtin function itertools.permutations.\n\nTo check whether a permutation represents a power of 2, we check that there is no leading zero, and divide out all factors of 2. If the result is 1 (that is, it contained no other factors besides 2), then it was a power of 2. In Python, we can use the check bin(N).count(\'1\') == 1.\n\n```\nTime Complexity: O((logN)!\u2217logN). Note that logN is the number of digits in the binary representation of N. For each of (logN)! permutations of the digits of N, we need to check that it is a power of 2 in O(logN) time.\n\nSpace Complexity: O(logN), the space used by A (or cand in Python).\n```\n\nApproach 1: C++\n\n\n```\nclass Solution {\npublic:\n    bool reorderedPowerOf2(int N) {\n        vector<int> digits;\n        while(N>0){\n            digits.push_back(N%10);\n            N /= 10;\n        }\n        \n        sort(digits.begin(), digits.end());        \n        do{\n            if( digits[0] != 0 && __builtin_popcount(digit2num(digits)) == 1)\n                return true;\n        }while(next_permutation(digits.begin(), digits.end()));\n        return false;\n    }\n    \nprivate:\n    int digit2num(vector<int>& digits){\n        int ans = 0;\n        for(auto digit: digits)\n            ans = ans * 10 + digit;\n        return ans;\n    }\n};\n```\n\nApproach 2: Python\n```\nclass Solution:\n    def reorderedPowerOf2(self, N: int) -> bool:\n        for cand in itertools.permutations(str(N)):\n            if cand[0]!=\'0\' and bin(int("".join(cand))).count(\'1\') ==1:\n                return True\n        return False\n        #return any( cand[0]!=\'0\' and bin(int("".join(cand))).count(\'1\') ==1\n        #           for cand in itertools.permutations(str(N)))\n            #for cand in iterationtools.permutation(str(N)))\n```\n\n\n\nIdea2: Counting\nIntuition and Algorithm\n\nWe can check whether two numbers have the same digits by comparing the count of their digits. For example, 338 and 833 have the same digits because they both have exactly two 3\'s and one 8.\nSince NN could only be a power of 2 with 9 digits or less (namely, 2^0, 2^1, 2^31), we can just check whether NN has the same digits as any of these possibilities.\n\nComplexity Analysis\n\nTime Complexity: O( (logN)^2). There are logN different candidate powers of 2, and each comparison has O(logN) time complexity.\nSpace Complexity: O(logN).\n\n\n```\nclass Solution(object):\n    def reorderedPowerOf2(self, N):\n        count = collections.Counter(str(N))\n        return any(count == collections.Counter(str(1 << b))\n                   for b in xrange(31))\n```\n\nReference:\n[1] https://leetcode.com/problems/reordered-power-of-2/solution/\n[2] itertools.permutations:\nIllustration:\n\nN=128\n\n>>> for cand in itertools.permutations(str(N)):print(cand)\n...\n(\'1\', \'2\', \'8\')\n(\'1\', \'8\', \'2\')\n(\'2\', \'1\', \'8\')\n(\'2\', \'8\', \'1\')\n(\'8\', \'1\', \'2\')\n(\'8\', \'2\', \'1\')\n>>> for cand in itertools.permutations([1,2,8]):print(cand)\n...\n(1, 2, 8)\n(1, 8, 2)\n(2, 1, 8)\n(2, 8, 1)\n(8, 1, 2)\n(8, 2, 1)
['Bit Manipulation', 'C', 'Python']