bool hasAlternatingBits(int n){ int temp=2; while(n){ if(temp == (n&1)) return false; temp=n&1; n>>=1; } return true; }