Skip to content

Instantly share code, notes, and snippets.

@avipars
Last active April 15, 2020 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avipars/df128df80da32256883af21cdc31fdd4 to your computer and use it in GitHub Desktop.
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
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;
}
}
@avipars
Copy link
Author

avipars commented Apr 15, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment