File tree 1 file changed +49
-0
lines changed
1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+ # 172. Factorial Trailing Zeroes
2
+
3
+ - Difficulty: Easy.
4
+ - Related Topics: Math.
5
+ - Similar Questions: Number of Digit One, Preimage Size of Factorial Zeroes Function.
6
+
7
+ ## Problem
8
+
9
+ Given an integer * n* , return the number of trailing zeroes in * n* !.
10
+
11
+ ** Example 1:**
12
+
13
+ ```
14
+ Input: 3
15
+ Output: 0
16
+ Explanation: 3! = 6, no trailing zero.
17
+ ```
18
+
19
+ ** Example 2:**
20
+
21
+ ```
22
+ Input: 5
23
+ Output: 1
24
+ Explanation: 5! = 120, one trailing zero.
25
+ ```
26
+
27
+ ** Note: ** Your solution should be in logarithmic time complexity.
28
+
29
+ ## Solution
30
+
31
+ ``` javascript
32
+ /**
33
+ * @param {number} n
34
+ * @return {number}
35
+ */
36
+ var trailingZeroes = function (n ) {
37
+ if (n === 0 ) return 0 ;
38
+ return Math .floor (n / 5 ) + trailingZeroes (Math .floor (n / 5 ));
39
+ };
40
+ ```
41
+
42
+ ** Explain:**
43
+
44
+ nope.
45
+
46
+ ** Complexity:**
47
+
48
+ * Time complexity : O(log(n)).
49
+ * Space complexity : O(1).
You can’t perform that action at this time.
0 commit comments