Power of Two
bit黑魔法一行解决
class Solution(object):
def isPowerOfTwo(self, n):
"""
:type n: int
:rtype: bool
"""
return n & (n - 1) == 0 if n > 0 else False
bit黑魔法一行解决
class Solution(object):
def isPowerOfTwo(self, n):
"""
:type n: int
:rtype: bool
"""
return n & (n - 1) == 0 if n > 0 else False