描述
求n!末尾零的数量
解决
只要求到能分解成多少个5即可,偶数的数量足够
class Solution {
public:
int trailingZeroes(int n) {
int cnt = 0;
while (n)
{
n /= 5;
cnt += n;
}
return cnt;
}
};
求n!末尾零的数量
只要求到能分解成多少个5即可,偶数的数量足够
class Solution {
public:
int trailingZeroes(int n) {
int cnt = 0;
while (n)
{
n /= 5;
cnt += n;
}
return cnt;
}
};