c++
class Solution {
public:
bool isPowerOfTwo(int n) {
if (n < 1)
return false;
return (n&(n - 1)) == 0;
}
};
python
class Solution(object):
def isPowerOfTwo(self, n):
"""
:type n: int
:rtype: bool
"""
if n < 1:
return False
return (n&(n-1))==0