diff --git a/problems/172.factorial-trailing-zeroes.md b/problems/172.factorial-trailing-zeroes.md index 5f1c95c51..59b25d862 100644 --- a/problems/172.factorial-trailing-zeroes.md +++ b/problems/172.factorial-trailing-zeroes.md @@ -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 * @@ -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) @@ -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) +```