"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
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;
}
}
No comments:
Post a Comment