Last active
April 15, 2020 13:04
-
-
Save avipars/df128df80da32256883af21cdc31fdd4 to your computer and use it in GitHub Desktop.
Java Code Answer for Number of Steps to Reduce a Number to Zero. https://link.medium.com/nqICUGZMH5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
// article: https://link.medium.com/nqICUGZMH5 | |
public int numberOfSteps (int num) { | |
int step = 0; | |
while(num!= 0) | |
{ | |
if(num % 2 == 0) //even | |
{ | |
step++; | |
num=num/2; | |
} | |
else {//odd | |
step++; | |
num--; | |
} | |
} | |
return step; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Article: https://link.medium.com/nqICUGZMH5