0
点赞
收藏
分享

微信扫一扫

leetcode:将数字变成 0 的操作次数

贵州谢高低 2022-01-31 阅读 96

在这里插入图片描述

class Solution:
    def numberOfSteps(self, num: int) -> int:
        ans = 0
        while num != 0:
            if num % 2 == 0:
                num //= 2
            else:
                num -= 1
            ans += 1
        
        return ans

总结:
大过年的,快乐模拟

举报

相关推荐

0 条评论