Skip to content

Instantly share code, notes, and snippets.

@cangoal
Last active March 25, 2016 14:44
Show Gist options
  • Save cangoal/4ca3cdd4769a0c2a5cc8 to your computer and use it in GitHub Desktop.
Save cangoal/4ca3cdd4769a0c2a5cc8 to your computer and use it in GitHub Desktop.
LeetCode - Factorial Trailing Zeroes
//
public int trailingZeroes(int n) {
int ret = 0;
while(n != 0){
ret += n/5;
n = n/5;
}
return ret;
}
//
public int trailingZeroes(int n) {
long x = 5;
int ret=0;
while(n>=x){
ret += n/x;
x *= 5;
}
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment