Skip to content

Commit c05a6f1

Browse files
author
applewjg
committed
Factorial Trailing Zeroes
Change-Id: I876626a1bc512ea53fd09c274f22d010cdc73371
1 parent 0618f12 commit c05a6f1

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

FactorialTrailingZeroes.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
Author: King, [email protected]
3+
Date: Dec 13, 2014
4+
Problem: Factorial Trailing Zeroes
5+
Difficulty: Easy
6+
Source: https://oj.leetcode.com/problems/factorial-trailing-zeroes/
7+
Notes:
8+
Given an integer n, return the number of trailing zeroes in n!.
9+
10+
Note: Your solution should be in logarithmic time complexity.
11+
12+
Solution: ...
13+
*/
14+
public class Solution {
15+
public int trailingZeroes(int n) {
16+
int res = 0;
17+
while (n != 0) {
18+
res += n / 5;
19+
n = n / 5;
20+
}
21+
return res;
22+
}
23+
}

0 commit comments

Comments
 (0)