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/
"Simplicity can't be bought later, it must be earned from the start" -- DB
Sunday, February 14, 2021
Leetcode Everyday: 1342. Number of Steps to Reduce a Number to Zero. Easy
Labels:
leetcode
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment