题解 | #小招喵跑步#

小招喵跑步

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

全部评论

相关推荐

真烦好烦真烦:牛友太有实力了
点赞 评论 收藏
分享
AAA专业长城贴瓷砖刘大爷:这样的简历我会直接丢进垃圾桶,花里胡哨的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务