Input: n = 1
Output: true
Explanation: 20 = 1
Input: n = 16
Output: true
Explanation: 24 = 16
Input: n = 3
Output: false
Input: n = 4
Output: true
Input: n = 5
Output: false
class Solution
{
public:
bool isPowerOfTwo(int n)
{
return (__builtin_popcount(n) == 1) && (n & 0x7FFFFFFF);
}
};