1342. Number of Steps to Reduce a Number to Zero

Обновлено: 2024-03-12
1 мин
[]

Содержание

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)
        )