来源:Leetcode
原帖:https://leetcode.com/problems/factorial-trailing-zeroes/
题目:
Given an integer n, return the number of trailing zeroes in n!.
Note: Your solution should be in logarithmic time complexity.
代码:
原帖:https://leetcode.com/problems/factorial-trailing-zeroes/
题目:
Given an integer n, return the number of trailing zeroes in n!.
Note: Your solution should be in logarithmic time complexity.
代码:
class Solution {
public:
int trailingZeroes(int n) {
if (n < 0) return 0;
int res = 0;
while (n) {
n /= 5;
res += n;
}
return res;
}
};
No comments:
Post a Comment