본문 바로가기

IT/코딩테스트

[Leetcode] 1342. Number of Steps to Reduce a Number to Zero

728x90

https://leetcode.com/problems/number-of-steps-to-reduce-a-number-to-zero/

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

'IT > 코딩테스트' 카테고리의 다른 글

[Leetcode] 383. Ransom Note  (0) 2023.08.11
[Leetcode] 511. Game Play Analysis I  (0) 2023.08.10
[Leetcode] 412. Fizz Buzz  (0) 2023.08.09
[Leetcode] 1672. Richest Customer Wealth  (0) 2023.08.08
[Leetcode] 1480. Running Sum of 1d Array  (0) 2023.08.07