Python one line code by using list count


  • 2
    L

    class Solution(object):
    def isPowerOfTwo(self, n):
    """
    :type n: int
    :rtype: bool
    """
    return n>0 and list(bin(n)).count('1') == 1


Log in to reply
 

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