[leedcode 172] Factorial Trailing Zeroes

Given an integer n, return the number of trailing zeroes in n!.

Note: Your solution should be in logarithmic time complexity.

public class Solution {
    public int trailingZeroes(int n) {
        //求几个0主要考虑的是5的个数
        if(n==0) return 0;
        int res=0;
        while(n>0){
            res+=n/5;
            n=n/5;
        }
        return res;
    }
}

 

posted @ 2015-08-02 17:41  ~每天进步一点点~  阅读(102)  评论(0编辑  收藏  举报