My solution with table


  • 0
    Y

    class Solution {
    public:
    int trailingZeroes(int n) {
    int count = 0;
    int limi[16] = {5,25,125,625,3125,15625,78125,390625,1953125,9765625,48828125,244140625,1220703125};
    int elem[16] = { 1, 6, 31,156,781,3906,19531,97656,488281,2441406,12207031,61035156,305175781};
    int tmp=n;
    for(int i=12;i>=0;i--)
    {
    while(tmp>=limi[i])
    {
    count+=elem[i];
    tmp-=limi[i];
    }
    }
    return count;
    }
    };


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.