-
-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy path172.java
More file actions
33 lines (30 loc) · 961 Bytes
/
172.java
File metadata and controls
33 lines (30 loc) · 961 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
__________________________________________________________________________________________________
sample 0 ms submission
class Solution {
// 非递归解法
public static int trailingZeroes(int n) {
if (n<5)return 0;
if (n<10)return 1;
return (n/5+ trailingZeroes(n/5));
}
}
__________________________________________________________________________________________________
sample 31896 kb submission
class Solution {
public int trailingZeroes(int n) {
int sum=5; int count = 0;
for (int i = 0; i < n; i++) {
if(n/sum>0){
count +=n/sum;
sum *=5;
if(sum >1220703125){
break;
}
}else{
break;
}
}
return count;
}
}
__________________________________________________________________________________________________