A 2ms Java solution, any improvements?


  • -2
    S

    public class FactorialTrailingZeroes {

    private final int[] pow5 = { 5, 25, 125, 625, 3125, 15625, 78125, 390625, 1953125, 9765625, 48828125, 244140625,
    		1220703125, -1 };
    
    public int trailingZeroes(int n) {
    	int sum = 0, t, i = 0;
    	while ((t = n / pow5[i++]) > 0)
    		sum += t;
    	return sum;
    }
    

    }

    could anyone propose a 1-ms solution?


Log in to reply
 

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