给定一个整数,编写一个函数来判断它是否是 2 的幂次方。
还是大佬太强了,一行搞定。。
class Solution(object):
def isPowerOfTwo(self, n):
"""
:type n: int
:rtype: bool
"""
return n > 0 and not (n&(n-1))
给定一个整数,编写一个函数来判断它是否是 2 的幂次方。
还是大佬太强了,一行搞定。。
class Solution(object):
def isPowerOfTwo(self, n):
"""
:type n: int
:rtype: bool
"""
return n > 0 and not (n&(n-1))