Fast cpp solution. Can you do, better than this?


#1

int Solution::trailingZeroes(int n) {
int count = 0;
for (int i = 5; n / i >= 1; i *= 5)
count += n / i;
return count;
}


#2

this is exact solution from gfg not a single word changed…
if you thought of this on your own then good or maybe u r the one who wrote article on gfg


#3

have this-

int Solution::trailingZeroes(int A) {

int sum=0,p=5;
while(A/p)
{
    sum+=A/p;
    p=p*5;
}
return sum;

}

You just need to find out total no. of multiples of 5, 55, 55*5, and so on.


#4

lol you got him good


#5
int Solution::trailingZeroes(int a) {
    int ans=0;
    while(a){
        a=a/5;
        ans+=a;
    }
    return ans;
}

#6

Yes, check below one.

int Solution::trailingZeroes(int A) {
int five = 5;
int ans = 0;
while(A/five > 0){
ans += A/five;
five *= 5;
}

return ans;

}