Javascript solution 140ms


  • 1
    M

    var trailingZeroes = function(n) {

    var ans = 0;
    //count the numbers of 5 in n!
    //ex. 25, ans = (25/5) + (5/5) = 6
    for (var i = n; i > 0; i = Math.floor(i/5)) {
        ans += Math.floor(i/5);
    }
    return ans;
    

    };


Log in to reply
 

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