Skip to content

Commit 11cebd6

Browse files
ybian19azl397985856
authored andcommitted
feat: 172.factorial-trailing-zeroes add Python3 implementation (azl397985856#104)
1 parent e89728e commit 11cebd6

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

problems/172.factorial-trailing-zeroes.md

+23-3
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,13 @@ Note: Your solution should be in logarithmic time complexity.
4444

4545
- 数论
4646

47-
4847
## 代码
4948

50-
```js
49+
* 语言支持:JS,Python
5150

51+
Javascript Code:
5252

53+
```js
5354
/*
5455
* @lc app=leetcode id=172 lang=javascript
5556
*
@@ -61,7 +62,7 @@ Note: Your solution should be in logarithmic time complexity.
6162
*/
6263
var trailingZeroes = function(n) {
6364
// tag: 数论
64-
65+
6566
// if (n === 0) return n;
6667

6768
// 递归: f(n) = n / 5 + f(n / 5)
@@ -74,3 +75,22 @@ var trailingZeroes = function(n) {
7475
return count;
7576
};
7677
```
78+
79+
Python Code:
80+
81+
```python
82+
class Solution:
83+
def trailingZeroes(self, n: int) -> int:
84+
count = 0
85+
while n >= 5:
86+
n = n // 5
87+
count += n
88+
return count
89+
90+
91+
# 递归
92+
class Solution:
93+
def trailingZeroes(self, n: int) -> int:
94+
if n == 0: return 0
95+
return n // 5 + self.trailingZeroes(n // 5)
96+
```

0 commit comments

Comments
 (0)