package leetcode.p1342; /** * @ProjectName: LeetCode * @FileName: Solution * @Author: 杨逸 * @Data:2024/4/9 14:20 * @Description: https://leetcode.cn/problems/number-of-steps-to-reduce-a-number-to-zero/ * 1342. 将数字变成 0 的操作次数 */ public class Solution { public int numberOfSteps(int num) { int count = 0; while (num != 0){ if (num%2==0){ num /= 2; }else { num--; } count++; } return count; } }