Skip to content

Commit 514b71d

Browse files
author
applewjg
committed
FactorialTrailingZeroes
Change-Id: Ib2890824124c904ffd7cc12048c2a1a359460826
1 parent 127aeba commit 514b71d

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

FactorialTrailingZeroes.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
15+
class Solution {
16+
public:
17+
int trailingZeroes(int n) {
18+
int res = 0;
19+
while (n) {
20+
res += n / 5;
21+
n /= 5;
22+
}
23+
return res;
24+
}
25+
};

0 commit comments

Comments
 (0)