```
int integerReplacement(int n) {
int counter = 0;
if(n == INT_MAX) return 32;
while(n > 1){
counter++;
if(n & 1)
if((n & 2) && n != 3) n++;
else n--;
else
n >>= 1;
}
return counter;
}
```