Number of Steps to Reduce a Number to Zero LeetCode solution in Java

1
class Solution {
2
public int numberOfSteps(int num) {
3
return helper(num, 0);
4
}
5

6
public int helper(int n, int c) {
7
if (n == 0) return c;
8
if (n % 2 == 0) { // check for even no.
9
return helper(n / 2, c + 1);
10
}
11

12
return helper(n - 1, c + 1);
13
}
14
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0