LeetCode :Factorial Trailing Zeroes

No comments
Problem:
https://leetcode.com/problems/factorial-trailing-zeroes/

Reference : http://www.mytechinterviews.com/how-many-trailing-zeros-in-100-factorial

#include<iostream>
using namespace std;
class Solution 
{
public:
      int trailingZeroes(int n) {
        int count = 0;
        long k = 5;
        while(n >= k)
        {
            count+=n/k;
            k*=5;
        }
        return count;
    }
};
int main()
{
	Solution s;
	cout<<s.trailingZeroes(100)<<endl;
}

No comments :