您的位置:首页 > 大数据 > 人工智能

Leetcode: Factorial Trailing Zeroes

2015-08-27 01:59 357 查看

Question

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.

Show Tags

Show Similar Problems

Solution

Analysis

Count how many factor 5 in n!

Code

[code]class Solution(object):
    def trailingZeroes(self, n):
        """
        :type n: int
        :rtype: int
        """

        res = 0
        while n!=0:
            res = res + n/5
            n /= 5

        return res
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: