LeetCode 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.

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

题意:找到阶乘结果最后面有多少个0

思路:判断这里面有多少个5就可以,也就是说在阶乘过程中可能出现的5

java代码:

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

你可能感兴趣的:(LeetCode 172. Factorial Trailing Zeroes)