Given an integer, write a function to determine if it is a power of two.

1
2
3
4
5
6
7
8
class Solution {
public:
bool isPowerOfTwo(int n) {
if (n <= 0)
return false;
return !(n & (n - 1));
}
};