One line solution in Python


  • 0
    D

    """
    class Solution(object):
    def isPowerOfTwo(self, n):
    """
    :type n: int
    :rtype: bool
    """
    return list(bin(n)[2:]).count("1") == 1 and bin(n)[0] != "-"
    """


Log in to reply
 

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