My solution but complex


  • 0
    V
    class Solution {
    public:
        int trailingZeroes(int n) {
            int divi = 1;
            int expo = log( n ) / log( 5 );
            for( int i = 0; i < expo; i++ )
                divi *= 5;
        
            int count = 0;
            int used = 0;
            int quot = 0;
            for( int j = divi; divi > 1; divi /= 5 )
            {
                quot = n / divi;
                count += ( quot - used ) * expo;
                used = quot;
                expo--;
            }
    
            return count;
        }
    };

Log in to reply
 

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