```
class Solution {
public:
bool isPowerOfTwo(int n) {
if (n <= 0) {
return false;
}
n &= (n - 1);
return n == 0;
}
};
```

the basic idea is that if n is a power of two, its binary form contains only one "1"

welcome to visit more answers on github.com/fanfank/leetcode