Easy recursive code.

```
int integerReplacement(int n) {
long long int ln = (long long int)n;
return integerReplacementLong(ln);
}
int integerReplacementLong(long long int ln)
{
if(ln<=1)
{
return 0;
}
if(!(ln%2))
{
return 1+integerReplacementLong(ln/2);
}
else
{
return 1+min(integerReplacementLong(ln+1),integerReplacementLong(ln-1));
}
}
```