您的位置:首页 > 大数据 > 人工智能

Factorial Trailing Zeroes

2015-07-27 19:28 330 查看


Factorial Trailing Zeroes

Given an integer n, return the number of trailing zeroes in n!.
Note: Your solution should be in logarithmic time complexity.
思路:有多少个2与5相乘,就有多少个0,由于2远多于5,就是算有多少个5。
class Solution {
public:
int trailingZeroes(int n) {
int len = 0;
while(n >= 5)
{
len = len + n/5;
n = n/5;
}
return len;
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: