题目:
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) {
int i = 0;
while (n >= 5) {
i += n / 5;
n /= 5;
}
return i;
}
};
时间: 2024-10-15 15:12:34