class Solution {
public:
bool isPowerOfTwo(int n) {
return method2(n);
}
private:
bool method1(int n) {
int cnt = 0;
while(n > 0) {
cnt += (n & 1);
n >>= 1;
}
return cnt == 1;
}
bool method2(int n) {
return (n > 0) && !(n & (n-1));
}
};