Skip to content

Latest commit

 

History

History
17 lines (13 loc) · 539 Bytes

1342.md

File metadata and controls

17 lines (13 loc) · 539 Bytes

Implement the algorithm through which non-negative integers are reduced to zero. For each non-negative integer supplied, count the number of operations performed by the algorith to reduce the number to zero.

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