My 2ms O(log) wit base 5 Java solution! Easy to understand!!!


  • 0
    H
    public int trailingZeroes(int n) {
        /**
         n:0--5--10-15-20-25-30-35-40-45
         0:0--1-- 2--3--4--6--7--8--9-10
    
         0: n/5 + n/25 + n/125 + ... + n/5^i 
        */
        int number = 0;
        while(n!=0){
            number += n/5;
            n /=5;
        }
        return number;
    }

Log in to reply
 

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