Simple c code logn time with explanation


  • -1
    B

    Formula is:floor(n/5)+floor(n/5^2)+floor(n/5^3)+floor(n/5^4)+floor(n/5^5)+----till n/5^i=0
    code:
    int trailingZeroes(int n) {
    long long int i=5,count=0,c=1,x;
    while(n/i){
    count+=(n/i);
    i*=5;
    }
    return count;
    }


Log in to reply
 

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