one line python

  • 0
    class Solution(object):
        def isPowerOfTwo(self, n):
            :type n: int
            :rtype: bool
            return False if n <= 0 else (math.log10(n) / math.log10(2)).is_integer()

    math: log(m, n) = log(x, n) / log(x, m)
    in this case: log(m, n) = log(10, n) / log(2, n)

Log in to reply

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