package leetcode;

/**
 * https://leetcode.com/problems/number-of-steps-to-reduce-a-number-to-zero/
 */
public class Problem1342 {
    public int numberOfSteps (int num) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1342 prob = new Problem1342();
        System.out.println(prob.numberOfSteps(14)); // 16
        System.out.println(prob.numberOfSteps(8)); // 4
        System.out.println(prob.numberOfSteps(123)); // 12
    }
}

package leetcode;

/**
 * https://leetcode.com/problems/number-of-steps-to-reduce-a-number-to-zero/
 */
public class Problem1342 {
    public int numberOfSteps (int num) {
        int answer = 0;
        int n = num;
        while (n > 0) {
            if (n % 2 == 0) {
                n /= 2;
            } else {
                n--;
            }
            answer++;
        }
        return answer;
    }
}

Solve problem 1342