Leetcode No.172 Factorial Trailing Zeroes阶乘后的0(c++实现)

时间:2021-08-17 15:15:16   收藏:0   阅读:27

1. 题目

https://leetcode.com/problems/factorial-trailing-zeroes/

2. 分析

这一题需要我们观察一下规律,可以发现,

综上,可以得到下述代码:

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

原文:https://www.cnblogs.com/yunmeng-shi/p/15151408.html

评论(0)
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!