Skip to main content

869. Reordered Power of 2

https://leetcode.com/problems/reordered-power-of-2/

Python

from collections import Counter
from itertools import permutations


class Solution:
def reorderedPowerOf2(self, n: int) -> bool:
nums = [int(''.join(cand)) for cand in permutations(str(n)) if cand[0] != '0']
return any(self.is_power_4(num) for num in nums)

@staticmethod
def is_power_4(num: int):
return bin(num).count('1') == 1