"Simplicity can't be bought later, it must be earned from the start" -- DB
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