Sharing simple java solution, runtime: 190ms


  • 0
    A
    public int trailingZeroes(int n) {
    	if (n < 4)
    		return 0;
    	double div = 0;
    	int power = 1;
    	int zeros = 0;
    	while (div < n) {
    		div = Math.pow(5, power);
    		zeros += (int) (n / div);
    		power++;
    	}
    	return zeros;
    }

Log in to reply
 

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