```
class Solution {
public boolean hasAlternatingBits(int n) {
int last=n%2,cur;
n=n/2;
while(n>0){
cur=n%2;
if(cur==last) return false;
last=cur;
n=n/2;
}
return true;
}
}
```