您的位置:首页 > 其它

题目:尾部的零

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;

}

};


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: