首页 > 代码库 > [LeetCode]172 Factorial Trailing Zeroes

[LeetCode]172 Factorial Trailing Zeroes

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

public class Solution {
    public int trailingZeroes(int n) {
        
        if (n <= 0)
            return 0; // Invalid input.
            
        // How many 5s, 25s, 125s ...
        int base = 5;
        int fives = 0;
        do
        {
            fives += n / d;
            base *= 5;
        }
        while (base <= n);
        
        return fives;
    }
}


[LeetCode]172 Factorial Trailing Zeroes