c++
class Solution {
public:
int trailingZeroes(int n) {
int cnt = 0;
long long i = 5;//int: overflow
while (n / i >= 1) {
cnt += n / i;
i *= 5;
}
return cnt;
}
};
python
class Solution(object):
def trailingZeroes(self, n):
"""
:type n: int
:rtype: int
"""
cnt = 0
i=5
while n/i >=1:
cnt += n/i
i *= 5
return cnt
reference:
https://leetcode.com/discuss/19847/simple-c-c-solution-with-detailed-explaination
http://blog.sina.com.cn/s/blog_7fde765101011cqs.html