```
int one = 0,zero=0;
while(n>0) {
if((n&1)==1){ one++;zero=0;}
else {zero++;one=0;}
if(one > 1 || zero > 1) return false;
n >>=1;
}
return true;
```