Factorial Trailing Zeroes
Given an integer n, return the number of trailing zeroes in n!.
Note: Your solution should be in logarithmic time complexity.
思路:有多少个2与5相乘,就有多少个0,由于2远多于5,就是算有多少个5。
class Solution {
public:
int trailingZeroes(int n) {
int len = 0;
while(n >= 5)
{
len = len + n/5;
n = n/5;
}
return len;
}
};