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

leetcode 172 Factorial Trailing Zeroes(难易度:Easy)

2015-08-31 11:21 155 查看

Factorial Trailing Zeroes

Given an integer n, return the number of trailing zeroes in n!.

Note: Your solution should be in logarithmic time complexity.

代码:

int trailingZeroes(int n) {
if(n == 0)
return 0;
int result = 0;
for (long long i = 5; n/i > 0; i *= 5)
result += n/i;
return result;
}

原题地址:https://leetcode.com/problems/factorial-trailing-zeroes/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  leetcode