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
标签:return,Power,#-,int,self,Two,bool,isPowerOfTwo,leetcode From: https://blog.51cto.com/u_11908275/6381015