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

来源:互联网 发布:知乎2.7.2 编辑:程序博客网 时间:2024/05/18 03:34

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/

0 0