```
class Solution(object):
def integerReplacement(self, n):
steps = 0
while n != 1:
if n % 2 == 0:
n /= 2
else:
x = (n-1)/2
if x % 2 == 0 or x == 1:
n -= 1
else:
n += 1
steps += 1
return steps
```