Number of Steps to Reduce a Number to Zero LeetCode solution in Python

1
# Runtime: 70 ms (Top 5.12%) | Memory: 13.9 MB (Top 52.31%)
2
class Solution:
3
def numberOfSteps(self, num: int) -> int:
4
count = 0
5
while num:
6
if num % 2:
7
num = num - 1
8
else:
9
num = num // 2
10
count += 1
11
return count

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0