|
1 | 1 | packagecom.fishercoder.solutions; |
2 | 2 |
|
3 | | -/** |
4 | | - * 1342. Number of Steps to Reduce a Number to Zero |
5 | | - * |
6 | | - * Given a non-negative integer num, return the number of steps to reduce it to zero. |
7 | | - * If the current number is even, you have to divide it by 2, otherwise, you have to subtract 1 from it. |
8 | | - * |
9 | | - * Example 1: |
10 | | - * Input: num = 14 |
11 | | - * Output: 6 |
12 | | - * Explanation: |
13 | | - * Step 1) 14 is even; divide by 2 and obtain 7. |
14 | | - * Step 2) 7 is odd; subtract 1 and obtain 6. |
15 | | - * Step 3) 6 is even; divide by 2 and obtain 3. |
16 | | - * Step 4) 3 is odd; subtract 1 and obtain 2. |
17 | | - * Step 5) 2 is even; divide by 2 and obtain 1. |
18 | | - * Step 6) 1 is odd; subtract 1 and obtain 0. |
19 | | - * |
20 | | - * Example 2: |
21 | | - * Input: num = 8 |
22 | | - * Output: 4 |
23 | | - * Explanation: |
24 | | - * Step 1) 8 is even; divide by 2 and obtain 4. |
25 | | - * Step 2) 4 is even; divide by 2 and obtain 2. |
26 | | - * Step 3) 2 is even; divide by 2 and obtain 1. |
27 | | - * Step 4) 1 is odd; subtract 1 and obtain 0. |
28 | | - * |
29 | | - * Example 3: |
30 | | - * Input: num = 123 |
31 | | - * Output: 12 |
32 | | - * |
33 | | - * Constraints: |
34 | | - * 0 <= num <= 10^6 |
35 | | - * */ |
36 | 3 | publicclass_1342 { |
37 | 4 | publicstaticclassSolution1 { |
38 | 5 | publicintnumberOfSteps(intnum) { |
|