Skip to content

Instantly share code, notes, and snippets.

@wszdwp
Created September 22, 2013 19:58
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 wszdwp/6663220 to your computer and use it in GitHub Desktop.
Save wszdwp/6663220 to your computer and use it in GitHub Desktop.
Cracking the interivew 19.2
public class Question192
{
public static int numZeros(int num) {
int count = 0;
if (num < 0) {
return -1;
}
for(int i = 5; num / i > 0; i *= 5) {
count += num / i;
}
return count;
}
public static void main(String[] args) {
int num = 25;
System.out.println( "Expected(6): " + numZeros(num) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment