Skip to content

Commit ddfcecc

Browse files
authored
feat(ml):$172.factorial-trailing-zeroes.md (#448)
1 parent e635046 commit ddfcecc

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

problems/172.factorial-trailing-zeroes.md

+36-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ https://leetcode-cn.com/problems/factorial-trailing-zeroes/
5757

5858
## 代码
5959

60-
* 语言支持:JS,Python
60+
* 语言支持:JS,Python,C++, Java
6161

6262
Javascript Code:
6363

@@ -106,6 +106,41 @@ class Solution:
106106
return n // 5 + self.trailingZeroes(n // 5)
107107
```
108108

109+
C++ Code:
110+
111+
```c++
112+
class Solution {
113+
public:
114+
int trailingZeroes(int n) {
115+
int res = 0;
116+
while(n >= 5)
117+
{
118+
n/=5;
119+
res += n;
120+
}
121+
return res;
122+
}
123+
};
124+
```
125+
126+
127+
Java Code:
128+
129+
```js
130+
class Solution {
131+
public int trailingZeroes(int n) {
132+
int res = 0;
133+
while(n >= 5)
134+
{
135+
n/=5;
136+
res += n;
137+
}
138+
return res;
139+
}
140+
}
141+
```
142+
143+
109144
**复杂度分析**
110145
- 时间复杂度:$O(logN)$
111146
- 空间复杂度:$O(1)$

0 commit comments

Comments
 (0)