My python solution


  • 1
    G
    class Solution:
        # @param {integer} n
        # @return {boolean}
        def isPowerOfTwo(self, n):
            if n <= 0:
                return False
            x = bin(n)[2:]
            sum = 0
            for i in x:
                sum += int(i)
            if sum>1:
                return False
            else:
                return True

Log in to reply
 

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