My 0ms C solution


  • 8
    U

    `
    int trailingZeroes(int n) {

    if (n == 0)
        return 0;
    return n/5 + trailingZeroes(n/5);
    

    }
    `


  • 0
    4

    the same but iterative:

        int trailingZeroes( int n )
        { 
            int c = n / 5;
            while( n /= 5 ) c += n / 5;
            return c; 
        }
    

Log in to reply
 

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