Skip to content

Commit 8ecb7de

Browse files
refactor 172
1 parent 26e700c commit 8ecb7de

File tree

1 file changed

+27
-9
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+27
-9
lines changed
Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,34 @@
11
package com.fishercoder.solutions;
2-
/**Given an integer n, return the number of trailing zeroes in n!.
2+
/**
3+
* 172. Factorial Trailing Zeroes
34
4-
Note: Your solution should be in logarithmic time complexity.*/
5+
Given an integer n, return the number of trailing zeroes in n!.
6+
7+
Example 1:
8+
9+
Input: 3
10+
Output: 0
11+
Explanation: 3! = 6, no trailing zero.
12+
13+
Example 2:
14+
15+
Input: 5
16+
Output: 1
17+
Explanation: 5! = 120, one trailing zero.
18+
19+
Note: Your solution should be in logarithmic time complexity.
20+
21+
*/
522
public class _172 {
623

24+
public static class Solution1 {
725
public int trailingZeroes(int n) {
8-
int result = 0;
9-
while (n > 4) {
10-
n /= 5;
11-
result += n;
12-
}
13-
return result;
26+
int result = 0;
27+
while (n > 4) {
28+
n /= 5;
29+
result += n;
30+
}
31+
return result;
1432
}
15-
33+
}
1634
}

0 commit comments

Comments
 (0)