Power of Two
Power of Two
Given an integer, write a function to determine if it is a power of two.
Example
Input: 1
Output: true
Explanation: 20 = 1
Input: 16
Output: true
Explanation: 24 = 16
Input: 218
Output: false
Solution
class Solution(object):
def isPowerOfTwo(self, n):
"""
:type n: int
:rtype: bool
"""
if n<=0:
return False
temp = bin(n)[2::1]
if temp.count('1') == 1:
return True
else:
return False
Result