lintcode 2.尾部的零
2018-02-20 12:04
357 查看
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 operators. m=1 q=0 l=0 if n<5: return 0 else: for i in range(1, n+1): m = m*i while l==0: l=m%10 m=m/10 q=q+1 return q-1 ''' 由于超过25数字过大,导致改为科学计数法,导致出错 ''' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
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 operators. m=1 num=0 for i in range(1,n+1): m=m*i str1=str(m) str1=str1[::-1] for w in str1: if int(w)!=0: break if int(w)==0: num=num+1 return num ''' 这个会出现超时问题 '''
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 operators. count = 0 while n>0: count=int(count+ n / 5 ) int(count) n = n/5 if n<1: n=int(n) count=int(count) return count'''
不知道怎么改一下程序了
'''
相关文章推荐
- 【LintCode】2、尾部的零
- lintcode 2:尾部的零
- lintcode 求n!尾部的零的数目
- LintCode 2.尾部的零 C++
- lintcode 2:尾部的零
- LintCode Java——尾部的零
- LintCode_尾部的零
- LintCode 2 尾部的零
- LintCode 2.尾部的零
- 【计算连乘积中末尾0的个数】LintCode 尾部的零
- [Lintcode] #2 尾部的零
- LintCode【简单】2. 尾部的零 。代码及思路
- lintcode-2-尾部的零
- Lintcode 2. 尾部的零
- LintCode 2.尾部的零
- LintCode Python 尾部的零
- Lintcode 尾部零的个数
- (lintcode)第2题尾部的零
- LintCode_002_尾部的零
- Lintcode 2: 尾部的零