File tree 1 file changed +23
-3
lines changed
1 file changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -44,12 +44,13 @@ Note: Your solution should be in logarithmic time complexity.
44
44
45
45
- 数论
46
46
47
-
48
47
## 代码
49
48
50
- ``` js
49
+ * 语言支持:JS,Python
51
50
51
+ Javascript Code:
52
52
53
+ ``` js
53
54
/*
54
55
* @lc app=leetcode id=172 lang=javascript
55
56
*
@@ -61,7 +62,7 @@ Note: Your solution should be in logarithmic time complexity.
61
62
*/
62
63
var trailingZeroes = function (n ) {
63
64
// tag: 数论
64
-
65
+
65
66
// if (n === 0) return n;
66
67
67
68
// 递归: f(n) = n / 5 + f(n / 5)
@@ -74,3 +75,22 @@ var trailingZeroes = function(n) {
74
75
return count;
75
76
};
76
77
```
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
+ ```
You can’t perform that action at this time.
0 commit comments