python - LintCode 2. 尾部的零
2018-03-30 10:38
459 查看
2. 尾部的零
设计一个算法,计算出n阶乘中尾部零的个数样例11! = 39916800,因此应该返回 2挑战 O(logN)的时间复杂度解决思路:n!尾部出现0必定满足其有因子为5或者5^m(m>1,且为整数)class Solution:
"""
@param: n: An integer
@return: An integer, denote the number of trailing zeros in n!
"""
def trailingZeros(self, n):
# write your code here, try to do it without arithmetic operator
result = 0
temp = n // 5
while temp != 0 :
result += temp
temp //= 5
return result
相关文章推荐
- LintCode Python 尾部的零
- LintCode【简单】2. 尾部的零 。代码及思路
- LintCode 第二题 计算阶乘结果尾部的零
- python_lintcode_100删除排序数组中的重复数字 _101删除排序数组中的重复数字2
- [LintCode]Longest Common Prefix(Python)
- [LintCode 406] Minimum Size Subarray Sum(Python)
- python_lintcode_困难题_54
- [LintCode 107] 单词切分(Python)
- lintcode python 代码 133 最长单词
- (lintcode)第2题尾部的零
- [Lintcode 397] 最长上升连续子序列(Python)
- LintCode笔记(6)——尾部的零
- [LintCode 109] 数字三角形(Python)
- LintCode 2 : 尾部的零(java实现)
- python_lintcode_372在O(1)时间复杂度删除链表节点_174删除链表中倒数第n个节点
- [LintCode 69] 二叉树的层次遍历 (Python)
- Lintcode 尾部零的个数
- [LintCode 78] 最长公共前缀(Python)
- python_lintcode_简单题_8旋转字符_420报数_197排列序号
- LintCode 2.尾部的零