leetcode学习笔记27

Given an integer n, return the number of trailing zeroes in n!.
Input: 3
Output: 0
Explanation: 3! = 6, no trailing zero.
2*5含有0,每个n都含有2,因此主要统计5的个数就可以了,25即两个5,125即三个5

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

猜你喜欢

转载自blog.csdn.net/weixin_38941866/article/details/85136104