C++:
class Solution {
public:
bool isPowerOfTwo(int n) {
int number = 1;
for ( int i = 1; i < 8 * sizeof(int); ++i ) {
if ( number == n ) {
return true;
} else if ( number > n ) {
return false;
}
number <<= 1;
}
return false;
}
};