leetcode 231. Power of Two

Given an integer, write a function to determine if it is a power of two.

class Solution(object):
    def isPowerOfTwo(self, n):
        """
        :type n: int
        :rtype: bool
        """
        #-4???
        if n >= 1:
            return n & (n-1) == 0
        else:
            return False
class Solution(object):
    def isPowerOfTwo(self, n):
        """
        :type n: int
        :rtype: bool
        """
        #-4???
        c = 0
        while n > 0:
            if n & 1:
                c += 1
            n >>= 1
        return c == 1                    
原文地址:https://www.cnblogs.com/bonelee/p/8859050.html