题解 | #求int型正整数在内存中存储时1的个数#

求int型正整数在内存中存储时1的个数

http://www.nowcoder.com/practice/440f16e490a0404786865e99c6ad91c9

递归

def to2(x, n = 0):
    if x%2 == 1:
        n += 1
    if x < 1:
        print(n)
    else:
        to2(x//2, n)

to2(int(input()))
全部评论

相关推荐

我估计&nbsp;&nbsp;应该是不招人了散了吧兄弟们
投递数字马力(杭州)信息技术有限公司等公司7个岗位 >
点赞 评论 收藏
转发
头像
不愿透露姓名的神秘牛友
03-13 10:56
点赞 评论 收藏
转发
1 收藏 评论
分享
牛客网
牛客企业服务