1342. Number of Steps to Reduce a Number to Zero
Question
Given an integer
num
, return the number of steps to reduce it to zero.In one step, if the current number is even, you have to divide it by
2
, otherwise, you have to subtract1
from it.
Solution
循环,当num不等于零时,如果为奇数则减一,如果为偶数则除以2。
每次循环记录次数。
Code
1 | class Solution { |
1342. Number of Steps to Reduce a Number to Zero
https://xuanhe95.github.io/2022/05/27/1342-Number-of-Steps-to-Reduce-a-Number-to-Zero/