Inverse exponential


  • 0
    T

    n = 2 ** x and x = log(n) / log(2)
    For 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()
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.