h*z
2 楼
//Java
public class Solution {
public int trailingZeroes(int n) {
int ret = 0;
for(long i=5;n/i>=1;i*=5)
ret +=n/i;
return ret;
}
}
有问题么?
public class Solution {
public int trailingZeroes(int n) {
int ret = 0;
for(long i=5;n/i>=1;i*=5)
ret +=n/i;
return ret;
}
}
有问题么?
g*t
4 楼
// Python
算法看了下攻略,自己实现一个
class Solution:
# @return an integer
def trailingZeroes(self, n):
# the number of zeroes depends on the pair of '2' * '5' . Obviously,
2 is more than 5 in n!. just count how many 5 are multiplied in factorial.
if n <= 0 : return 0
res = 0
size = 0
while n != 0:
size = n / 5
res += size
n = size
return res
算法看了下攻略,自己实现一个
class Solution:
# @return an integer
def trailingZeroes(self, n):
# the number of zeroes depends on the pair of '2' * '5' . Obviously,
2 is more than 5 in n!. just count how many 5 are multiplied in factorial.
if n <= 0 : return 0
res = 0
size = 0
while n != 0:
size = n / 5
res += size
n = size
return res
z*c
8 楼
public int trailingZeroes(int n) {
int count = 0;
while (n > 0) {
count += n/5;
n /= 5;
}
return count;
}
int count = 0;
while (n > 0) {
count += n/5;
n /= 5;
}
return count;
}
相关阅读
急问:offer letter出来了还能negotiate么?问一个关于reference的问题[合集] 新手弱问:如何 negotiate salary (包子答谢)祝贺两孩妈成功转行,得加拿大 Utility公司job Offer有没有嵌入式的工作机会啊?诚心请教一个start up的offera家的电面多快有消息?I-765收据没有收到请问H1B多久知道结果请教,Expedia Senior SDET预期是什么样的offer package?函数atoi的实现用offer letter申请OPT是否必须去给Offer的公司工作?Marvell这个公司怎么样?女生去大公司做码农,还是去学校做博后?[合集] 攒RP,跟大家分享一些找工经验和教训(非工科)[合集] LG找工作一年上来求建议成功转行没几招,学会一招足够了.求安慰兼bless今年就业形势是比往年差吧H-4 在今年9月 expire, 4月file H-1, 需要file H-4 extension吗?