您的位置:首页 > 编程语言 > Python开发

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 python