-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path172.factorial-trailing-zeroes.cpp
More file actions
64 lines (62 loc) · 990 Bytes
/
172.factorial-trailing-zeroes.cpp
File metadata and controls
64 lines (62 loc) · 990 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* @lc app=leetcode id=172 lang=cpp
*
* [172] Factorial Trailing Zeroes
*
* https://leetcode.com/problems/factorial-trailing-zeroes/description/
*
* algorithms
* Easy (38.31%)
* Likes: 1189
* Dislikes: 1350
* Total Accepted: 245.8K
* Total Submissions: 637.6K
* Testcase Example: '3'
*
* Given an integer n, return the number of trailing zeroes in n!.
*
* Follow up: Could you write a solution that works in logarithmic time
* complexity?
*
*
* Example 1:
*
*
* Input: n = 3
* Output: 0
* Explanation: 3! = 6, no trailing zero.
*
*
* Example 2:
*
*
* Input: n = 5
* Output: 1
* Explanation: 5! = 120, one trailing zero.
*
*
* Example 3:
*
*
* Input: n = 0
* Output: 0
*
*
*
* Constraints:
*
*
* 0 <= n <= 10^4
*
*
*/
// @lc code=start
class Solution {
public:
int trailingZeroes(int n) {
if (n == 0)
return 0;
return n / 5 + trailingZeroes(n / 5);
}
};
// @lc code=end