LeetCode--Factorial Trailing Zeroes(阶乘的末位0数)

来源:互联网 发布:美恰软件 编辑:程序博客网 时间:2024/06/05 17:07

题目:

给定数字n,返回n!对应数字中的末尾0的个数。

解题思路:

判断末尾0的个数,直接查看之前的数字里头包含5的个数或5的倍数的个数,数字5,包含一个5,数字10包含两个(5,10),15包含三个(5,10,15)。。。25包含六个(5,10,15,20,5*5)

代码(Python):

class Solution(object):    def trailingZeroes(self, n):        """        :type n: int        :rtype: int        """        count = 0        while(n):            count = count+n/5            n = n/5        return count

阅读全文
0 0
原创粉丝点击