采用递归的算法来实现阶乘的结尾零的数量
#include <iostream>
using namespace std
;
class Solution
{
public:
long long trailingZeros(long long n
)
{
int num
= multi(n
);
int count
= 0;
while ((num
% 10) == 0)
{
count
++;
num
= num
/ 10;
}
return count
;
}
private:
int multi(long long n
)
{
if (n
== 1)
{
return n
;
}
return n
* multi(n
- 1);
}
};
转载请注明原文地址:https://ipadbbs.8miu.com/read-52387.html