Python Solution | Detailed Explanation with Example
Intuition\n Describe your first thoughts on how to solve this problem. \nWe know that in this question, the input n is less and equal to 10\u2079 so the powers 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe know that in this question, the input n is less and equal to 10\u2079 so the powers of 2 can be 1, 2, 4, and 8 all the way up to 2 to the power of 29 since 2\xB2\u2079 is less than 10\u2079 and 10\u2079 is less than 2\xB3\u2070.\n\n![image.png](https://assets.leetcode.com/users/images/19613664-10f3-4d4f-8440-7c0698bba38c_1675118248.3209496.png)\n\nSince We can reorder the digits in any order, input 218 can be reordered into 128 which is 2 to the power of 7. On the other hand, input 123 returns false since all the combinations of 123 [213, 123, 132, 231, 213, 312, 321] are not the power of 2.\n\nThe observation we can make is that reordering digits of a number in any order does not change the number of occurrences of its digits. So the main idea behind solving this question is that we want to count the occurrence of each digit in the input N and compare it with the occurrence of each digit in the powers of 2. If the occurrences are the same, it means that we can reorder the digits of N to have the resulting number as a power of 2. If the occurrence is not the same, it means we can\u2019t reorder the digits to become a power of 2.\n\n![image.png](https://assets.leetcode.com/users/images/e85c5861-3926-4f48-8adc-f48a3336c06c_1675118345.1014912.png)\n\nIf we consider the previous example, 218 returns true since 218 and 128 = 2\u2077 both have one 1, one 2, and one 8. 123 returns false since it does not match any powers of 2.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe start by converting the given number ```N``` to a string and then using the counter method to count the occurrences of each digit in ```N```. We use the variable ```occurrence``` to store the result. \nNext, we will use a for loop to iterate through the range of 0 to 29. In each iteration, we compare the occurrence of each digit in 2 to the power of i to the occurrences of each digit of the given number ```N```. if they are the same, we return ```True```, otherwise, we increment i and keep comparing. \nIf the loop completes and no match is found, it means the digits of ```N``` cannot be reordered to form a power of 2, we return ```False```.\n\n\n# Code\n```\nclass Solution(object):\n    def reorderedPowerOf2(self, n):\n        """\n        :type n: int\n        :rtype: bool\n        """\n        occurrence = Counter(str(n))\n        for i in range(30):\n            if (occurrence == Counter(str(2**i))):\n                return True\n        return False\n\n\n```\n\nCheck out the video solution for this problem:\nhttps://www.youtube.com/watch?v=4FAdMIoqRes\n
['Python']