Factorial Trailing Zeroes
Given an integer n, return the number of trailing zeroes in n!.
Note: Your solution should be in logarithmic time complexity.
Credits:
Special thanks to @ts for adding this problem and creating all test cases.
- int trailingZeroes(int n) {
- int base = 5;
- int cnt = 0;
- while(n>=base) {
- cnt += n/base;
- base *= 5;
- }
- return cnt;
- }

浙公网安备 33010602011771号