class Solution {
public:
bool isPowerOfTwo(int n) {
if(n < 0) return false;
int count = 0;
for(int i = 31; i >=0 ;i)
if(((1 << i)&n) != 0) count++;
return count == 1;
}
};
A 8ms Straightforward Bit Manipulation C++ Solution

class Solution { //8ms public: bool isPowerOfTwo(int n) { if (n < 0 ) return false; while (n > 1) n = DividedByTwo (n); if (n == 1) return true; if (n == 0) return false; } private: int DividedByTwo (int n) { int quo; int rem; quo = n/2; rem = n%2; if (rem != 0) return 0; if (rem == 0) return quo; } };