n = 2 ** x and
x = log(n) / log(2)
n to be power of 2
x has to be an integer.
def isPowerOfTwo(n): return n > 0 and (math.log10(n) / math.log10(2)).is_integer()
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.