class Solution {
public:
bool hasAlternatingBits(int n) {
int z = n%2;
n/=2;
while(n)
{
int c = n%2;
if(z^c == 0) return false;
n/=2;
z = c;
}
return true;
}
};