美文网首页
172. Factorial Trailing Zeroes

172. Factorial Trailing Zeroes

作者: a_void | 来源:发表于2016-09-23 12:27 被阅读0次

Given an integer n, return the number of trailing zeroes in n!.
**Note: **Your solution should be in logarithmic time complexity.

Solution:

class Solution {
public:
    int trailingZeroes(int n) {
        int r = 0;
        while(n >= 5){
            n = n / 5;
            r+=n;
        }
        return r;
    }
};

相关文章

网友评论

      本文标题:172. Factorial Trailing Zeroes

      本文链接:https://www.haomeiwen.com/subject/ysytyttx.html