1342. Number of Steps to Reduce a Number to Zero

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1342

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