Last active
March 25, 2016 14:44
-
-
Save cangoal/4ca3cdd4769a0c2a5cc8 to your computer and use it in GitHub Desktop.
LeetCode - Factorial Trailing Zeroes
This file contains hidden or 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
| // | |
| 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