231. Power of Two
Input:1
Output:true
Explanation: 2^0 = 1Input:16
Output:true
Explanation: 2^4 = 16Input:218
Output:falseLast updated
Was this helpful?
Input:1
Output:true
Explanation: 2^0 = 1Input:16
Output:true
Explanation: 2^4 = 16Input:218
Output:falseLast updated
Was this helpful?
Was this helpful?
class Solution(object):
def isPowerOfTwo(self, n):
"""
:type n: int
:rtype: bool
"""
return False if n<= 0 else (n & (n-1)) == 0