Dashboard Temp Share Shortlinks Frames API

HTMLify

LeetCode - Number of Steps to Reduce a Number to Zero - C
Views: 4 | Author: abh
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
// @leet start
int numberOfSteps(int num) {
    int steps = 0;
    while (num != 0) {
        if (num % 2) {
            num -= 1;
        } else {
            num /= 2;
        }
        steps++;
    }
    return steps;
}
// @leet end