LeetCode 172. 阶乘后的零C#
原题链接
简单
作者:
hpstory
,
2022-06-23 15:47:32
,
所有人可见
,
阅读 104
C# 代码
public class Solution {
public int TrailingZeroes(int n) {
int two = 0, five = 0;
for (int i = 1; i <= n; i++){
int result = i;
while (result % 2 == 0){
result /= 2;
two++;
}
while (result % 5 == 0){
result /= 5;
five++;
}
}
return Math.Min(two, five);
}
}
C# 代码
// 5的数量一定是最小的
public class Solution {
public int TrailingZeroes(int n) {
int five = 0;
for (int i = 1; i <= n; i++){
int result = i;
while (result % 5 == 0){
result /= 5;
five++;
}
}
return five;
}
}