```
public int integerReplacement(int n) {
int count = 0;
return helper((long)n, count);
}
public int helper(long n , int count){
if(n == 1) return count;
if(n%2==0) return helper(n/2, count+1);
return Math.min(helper(n+1, count+1), helper(n-1, count+1));
}```
```