题目:尾部的零
2015-08-19 19:18
316 查看
设计一个算法,计算出n阶乘中尾部零的个数
您在真实的面试中是否遇到过这个题?
Yes
哪家公司问你的这个题?
Airbnb
Alibaba
Amazon Apple
Baidu Bloomberg
Cisco Dropbox
Ebay Facebook
Google Hulu
Intel Linkedin
Microsoft NetEase
Nvidia Oracle
Pinterest Snapchat
Tencent Twitter
Uber Xiaomi
Yahoo Yelp
Zenefits
感谢您的反馈
样例
11! = 39916800,因此应该返回
2
挑战
O(logN)的时间复杂度
标签 Expand
数学
相关题目 Expand
class Solution {
/*
* param n: As desciption
* return: An integer, denote the number of trailing zeros in n!
*/
public long trailingZeros(long n) {
// write your code here
if(n==0) return 0;
int count = 0;
while(n>=5){
n = (int) (n/5);
count +=n;
}
return count;
}
};
您在真实的面试中是否遇到过这个题?
Yes
哪家公司问你的这个题?
Airbnb
Alibaba
Amazon Apple
Baidu Bloomberg
Cisco Dropbox
Ebay Facebook
Google Hulu
Intel Linkedin
Microsoft NetEase
Nvidia Oracle
Pinterest Snapchat
Tencent Twitter
Uber Xiaomi
Yahoo Yelp
Zenefits
感谢您的反馈
样例
11! = 39916800,因此应该返回
2
挑战
O(logN)的时间复杂度
标签 Expand
数学
相关题目 Expand
class Solution {
/*
* param n: As desciption
* return: An integer, denote the number of trailing zeros in n!
*/
public long trailingZeros(long n) {
// write your code here
if(n==0) return 0;
int count = 0;
while(n>=5){
n = (int) (n/5);
count +=n;
}
return count;
}
};
相关文章推荐
- ItailorCode
- ajax(三) ajax提交表单、ajax实现文件上传
- 什么是进程
- 第十章 面向对象编程:继承和多态
- 题目:将整数A转换为B
- oracle游标:查询并打印员工的姓名和薪水
- iOS中Storyboard使用要点记录
- EF里Guid类型数据的自增长、时间戳和复杂类型的用法
- 题目:字符串查找
- NIO(JDK1.4)--选择器Selector
- 阿里云server安全设定
- 时间戳
- OC中nil、Nil、NULL、NSNull的区别
- android开发 解决启动页空白或黑屏问题
- iOS面试题三
- libcoubase源码解析
- 多线程
- webx turbine 前端开发入门理解
- 汇编中精妙的流程控制
- SQL