public class Solution {
public int NumberOfSteps (int num) {
int steps = 0;
while (num > 0) {
++steps;
num = num % 2 == 0 ? num / 2 : num - 1;
}
return steps;
}
}
Source: https://leetcode.com/problems/number-of-steps-to-reduce-a-number-to-zero/
No comments:
Post a Comment