Skip to content

Commit

Permalink
feat: 172.factorial-trailing-zeroes add Python3 implementation (azl39…
Browse files Browse the repository at this point in the history
  • Loading branch information
ybian19 authored and azl397985856 committed Aug 12, 2019
1 parent e89728e commit 11cebd6
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions problems/172.factorial-trailing-zeroes.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ Note: Your solution should be in logarithmic time complexity.

- 数论


## 代码

```js
* 语言支持:JS,Python

Javascript Code:

```js
/*
* @lc app=leetcode id=172 lang=javascript
*
Expand All @@ -61,7 +62,7 @@ Note: Your solution should be in logarithmic time complexity.
*/
var trailingZeroes = function(n) {
// tag: 数论

// if (n === 0) return n;

// 递归: f(n) = n / 5 + f(n / 5)
Expand All @@ -74,3 +75,22 @@ var trailingZeroes = function(n) {
return count;
};
```

Python Code:

```python
class Solution:
def trailingZeroes(self, n: int) -> int:
count = 0
while n >= 5:
n = n // 5
count += n
return count


# 递归
class Solution:
def trailingZeroes(self, n: int) -> int:
if n == 0: return 0
return n // 5 + self.trailingZeroes(n // 5)
```

0 comments on commit 11cebd6

Please sign in to comment.