Factorial Trailing Zeroes
Given an integer n, return the number of trailing zeroes in n!.
Note: Your solution should be in logarithmic time complexity.
要求时间复杂度为log型
int trailingZeroes(int n) { int ret = 0; while(n) { ret += n/5; n /= 5; } return ret; }
- 2 * 5 则会出现一个0;2出现的次数比5多;所以只要得到多少个5相乘就可以了