Factorial Trailing Zeroes N!末尾0的个数

来源:互联网 发布:四知的学法指导 编辑:程序博客网 时间:2024/06/06 07:05

Factorial Trailing Zeroes

 

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

Note: Your solution should be in logarithmic time complexity.

Credits:
Special thanks to @ts for adding this problem and creating all test cases.

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

0 0