题解 | #小招喵跑步#
小招喵跑步
https://www.nowcoder.com/practice/1177e9bd1b5e4e00bd39ca4ea9e4e216
x = int(input())
n = 0
def getstep(x, step):
step += 1
if x == 1:
res.append(step)
step -= 1
elif x < 0:
step -= 1
getstep(-x, step)
else:
if x % 2 == 0:
getstep(x / 2, step)
else:
getstep(x - 1, step)
getstep(x + 1, step)
step = 0
res = []
if x == 0:
print(step)
else:
step = getstep(x, step)
print(min(res))
递归
不允许题解没有python
查看11道真题和解析