231. 2的幂

 

231. 2的幂

 

方法一

class Solution(object):
    def isPowerOfTwo(self, n):
        """
        :type n: int
        :rtype: bool
        """
        return n > 0 and not (n & (n - 1))

"""
class Solution:
    def isPowerOfTwo(self, n):
        """
        :type n: int
        :rtype: bool
        """
        if n<=0:
            return False
        return n&(n-1) == 0

"""

 

 

posted @ 2019-01-19 16:54  小学弟-  阅读(104)  评论(0编辑  收藏  举报