869. Reordered Power of 2
Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 62% Topics: Hash Table, Math, Sorting, Counting, Enumeration
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O((logn)^2) = O(1) due to n is a 32-bit number
# Space: O(logn) = O(1)
import collections
class Solution(object):
def reorderedPowerOf2(self, N):
"""
:type N: int
:rtype: bool
"""
count = collections.Counter(str(N))
return any(count == collections.Counter(str(1 << i))
for i in xrange(31))
Solution from kamyu104/LeetCode-Solutions · MIT